Handler sending logs to browser's javascript console with no browser extension required.
More...
|
static | send () |
| Convert records to javascript console commands and send it to the browser. More...
|
|
static | reset () |
| Forget all logged records. More...
|
|
Handler sending logs to browser's javascript console with no browser extension required.
- Author
- Olivier Poitrey rs@da.nosp@m.ilym.nosp@m.otion.nosp@m..com
Definition at line 21 of file BrowserConsoleHandler.php.
◆ call()
static Monolog\Handler\BrowserConsoleHandler::call |
( |
| ) |
|
|
staticprivate |
Definition at line 218 of file BrowserConsoleHandler.php.
220 $args = func_get_args();
221 $method = array_shift($args);
223 return self::call_array($method, $args);
◆ call_array()
static Monolog\Handler\BrowserConsoleHandler::call_array |
( |
|
$method, |
|
|
array |
$args |
|
) |
| |
|
staticprivate |
◆ dump()
static Monolog\Handler\BrowserConsoleHandler::dump |
( |
|
$title, |
|
|
array |
$dict |
|
) |
| |
|
staticprivate |
Definition at line 194 of file BrowserConsoleHandler.php.
References $key, $title, and array.
197 $dict = array_filter($dict);
201 $script[] = self::call(
'log', self::quote(
'%c%s'), self::quote(
'font-weight: bold'), self::quote(
$title));
202 foreach ($dict as
$key => $value) {
203 $value = json_encode($value);
205 $value = self::quote(
'');
207 $script[] = self::call(
'log', self::quote(
'%s: %o'), self::quote(
$key), $value);
Create styles array
The data for the language used.
◆ generateScript()
static Monolog\Handler\BrowserConsoleHandler::generateScript |
( |
| ) |
|
|
staticprivate |
Definition at line 133 of file BrowserConsoleHandler.php.
References $records, and array.
137 $context = self::dump(
'Context', $record[
'context']);
138 $extra = self::dump(
'Extra', $record[
'extra']);
140 if (empty($context) && empty($extra)) {
141 $script[] = self::call_array(
'log', self::handleStyles($record[
'formatted']));
143 $script = array_merge($script,
144 array(self::call_array(
'groupCollapsed', self::handleStyles($record[
'formatted']))),
147 array(self::call(
'groupEnd'))
152 return "(function (c) {if (c && c.groupCollapsed) {\n" . implode(
"\n", $script) .
"\n}})(console);";
Create styles array
The data for the language used.
◆ getDefaultFormatter()
Monolog\Handler\BrowserConsoleHandler::getDefaultFormatter |
( |
| ) |
|
|
protected |
Formatted output may contain some formatting markers to be transferred to console.log
using the c format.
Example of formatted string:
You can do [[blue text]]{color: blue} or [[green background]]{background-color: green; color: white}
Definition at line 35 of file BrowserConsoleHandler.php.
37 return new LineFormatter(
'[[%channel%]]{macro: autolabel} [[%level_name%]]{font-weight: bold} %message%');
◆ getResponseFormat()
static Monolog\Handler\BrowserConsoleHandler::getResponseFormat |
( |
| ) |
|
|
staticprotected |
Checks the format of the response.
If Content-Type is set to application/javascript or text/javascript -> js If Content-Type is set to text/html, or is unset -> html If Content-Type is anything else -> unknown
- Returns
- string One of 'js', 'html' or 'unknown'
Definition at line 113 of file BrowserConsoleHandler.php.
References $header.
116 foreach (headers_list() as
$header) {
117 if (stripos($header,
'content-type:') === 0) {
120 if (stripos($header,
'application/javascript') !==
false || stripos($header,
'text/javascript') !==
false) {
123 if (stripos($header,
'text/html') ===
false) {
◆ handleCustomStyles()
static Monolog\Handler\BrowserConsoleHandler::handleCustomStyles |
( |
|
$style, |
|
|
|
$string |
|
) |
| |
|
staticprivate |
Definition at line 174 of file BrowserConsoleHandler.php.
References $m, $style, and array.
176 static $colors =
array(
'blue',
'green',
'red',
'magenta',
'orange',
'black',
'grey');
177 static $labels =
array();
179 return preg_replace_callback(
'/macro\s*:(.*?)(?:;|$)/',
function (
$m) use ($string, &$colors, &$labels) {
180 if (trim(
$m[1]) ===
'autolabel') {
182 if (!isset($labels[$string])) {
183 $labels[$string] = $colors[count($labels) % count($colors)];
185 $color = $labels[$string];
187 return "background-color: $color; color: white; border-radius: 3px; padding: 0 2px 0 2px";
Create styles array
The data for the language used.
◆ handleStyles()
static Monolog\Handler\BrowserConsoleHandler::handleStyles |
( |
|
$formatted | ) |
|
|
staticprivate |
Definition at line 155 of file BrowserConsoleHandler.php.
References $format, and array.
157 $args =
array(self::quote(
'font-weight: normal'));
159 preg_match_all(
'/\[\[(.*?)\]\]\{([^}]*)\}/s',
$format, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
161 foreach (array_reverse($matches) as $match) {
162 $args[] = self::quote(self::handleCustomStyles($match[2][0], $match[1][0]));
163 $args[] =
'"font-weight: normal"';
166 $format = substr(
$format, 0, $pos) .
'%c' . $match[1][0] .
'%c' . substr(
$format, $pos + strlen($match[0][0]));
169 array_unshift($args, self::quote(
$format));
Create styles array
The data for the language used.
◆ quote()
static Monolog\Handler\BrowserConsoleHandler::quote |
( |
|
$arg | ) |
|
|
staticprivate |
◆ registerShutdownFunction()
Monolog\Handler\BrowserConsoleHandler::registerShutdownFunction |
( |
| ) |
|
|
protected |
◆ reset()
static Monolog\Handler\BrowserConsoleHandler::reset |
( |
| ) |
|
|
static |
◆ send()
static Monolog\Handler\BrowserConsoleHandler::send |
( |
| ) |
|
|
static |
Convert records to javascript console commands and send it to the browser.
This method is automatically called on PHP shutdown if output is HTML or Javascript.
Definition at line 59 of file BrowserConsoleHandler.php.
References $format, and $records.
61 $format = self::getResponseFormat();
68 self::writeOutput(
'<script>' . self::generateScript() .
'</script>');
70 self::writeOutput(self::generateScript());
◆ write()
Monolog\Handler\BrowserConsoleHandler::write |
( |
array |
$record | ) |
|
|
protected |
◆ writeOutput()
static Monolog\Handler\BrowserConsoleHandler::writeOutput |
( |
|
$str | ) |
|
|
staticprotected |
◆ $initialized
Monolog\Handler\BrowserConsoleHandler::$initialized = false |
|
staticprotected |
◆ $records
Monolog\Handler\BrowserConsoleHandler::$records = array() |
|
staticprotected |
The documentation for this class was generated from the following file: