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...
|
|
|
Public Member Functions inherited from Monolog\Handler\AbstractProcessingHandler |
| handle (array $record) |
| {Handles a record.All records may be passed to this method, and the handler should discard those that it does not want to handle.The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.- Parameters
-
array | $record | The record to handle |
- Returns
- Boolean true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
} More...
|
|
Public Member Functions inherited from Monolog\Handler\AbstractHandler |
| __construct ($level=Logger::DEBUG, $bubble=true) |
|
| isHandling (array $record) |
| {Checks whether the given record will be handled by this handler.This is mostly done for performance reasons, to avoid calling processors for nothing.Handlers should still check the record levels within handle(), returning false in isHandling() is no guarantee that handle() will not be called, and isHandling() might not be called for a given record.- Parameters
-
array | $record | Partial log record containing only a level key |
- Returns
- Boolean
} More...
|
|
| handleBatch (array $records) |
| {Handles a set of records at once.- Parameters
-
array | $records | The records to handle (an array of record arrays) |
} More...
|
|
| close () |
| Closes the handler. More...
|
|
| pushProcessor ($callback) |
| {Adds a processor in the stack.- Parameters
-
- Returns
- self
} More...
|
|
| popProcessor () |
| {Removes the processor on top of the stack and returns it.- Returns
- callable
} More...
|
|
| setFormatter (FormatterInterface $formatter) |
| {Sets the formatter.- Parameters
-
FormatterInterface | $formatter | |
- Returns
- self
} More...
|
|
| getFormatter () |
| {Gets the formatter.- Returns
- FormatterInterface
} More...
|
|
| setLevel ($level) |
| Sets minimum logging level at which this handler will be triggered. More...
|
|
| getLevel () |
| Gets minimum logging level at which this handler will be triggered. More...
|
|
| setBubble ($bubble) |
| Sets the bubbling behavior. More...
|
|
| getBubble () |
| Gets the bubbling behavior. More...
|
|
| __destruct () |
|
Protected Attributes inherited from Monolog\Handler\AbstractHandler |
| $level = Logger::DEBUG |
|
| $bubble = true |
|
| $formatter |
|
| $processors = array() |
|
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 180 of file BrowserConsoleHandler.php.
182 $args = func_get_args();
183 $method = array_shift($args);
185 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 156 of file BrowserConsoleHandler.php.
159 $dict = array_filter($dict);
163 $script[] = self::call(
'log', self::quote(
'%c%s'), self::quote(
'font-weight: bold'), self::quote($title));
164 foreach ($dict as $key => $value) {
165 $value = json_encode($value);
167 $value = self::quote(
'');
169 $script[] = self::call(
'log', self::quote(
'%s: %o'), self::quote($key), $value);
◆ generateScript()
static Monolog\Handler\BrowserConsoleHandler::generateScript |
( |
| ) |
|
|
staticprivate |
Definition at line 95 of file BrowserConsoleHandler.php.
References $records.
99 $context = self::dump(
'Context', $record[
'context']);
100 $extra = self::dump(
'Extra', $record[
'extra']);
102 if (empty($context) && empty($extra)) {
103 $script[] = self::call_array(
'log', self::handleStyles($record[
'formatted']));
105 $script = array_merge($script,
106 array(self::call_array(
'groupCollapsed', self::handleStyles($record[
'formatted']))),
109 array(self::call(
'groupEnd'))
114 return "(function (c) {if (c && c.groupCollapsed) {\n" . implode(
"\n", $script) .
"\n}})(console);";
◆ 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 36 of file BrowserConsoleHandler.php.
38 return new LineFormatter(
'[[%channel%]]{macro: autolabel} [[%level_name%]]{font-weight: bold} %message%');
◆ handleCustomStyles()
static Monolog\Handler\BrowserConsoleHandler::handleCustomStyles |
( |
|
$style, |
|
|
|
$string |
|
) |
| |
|
staticprivate |
Definition at line 136 of file BrowserConsoleHandler.php.
References $style.
138 static $colors = array(
'blue',
'green',
'red',
'magenta',
'orange',
'black',
'grey');
139 static $labels = array();
141 return preg_replace_callback(
'/macro\s*:(.*?)(?:;|$)/',
function ($m) use ($string, &$colors, &$labels) {
142 if (trim($m[1]) ===
'autolabel') {
144 if (!isset($labels[$string])) {
145 $labels[$string] = $colors[count($labels) % count($colors)];
147 $color = $labels[$string];
149 return "background-color: $color; color: white; border-radius: 3px; padding: 0 2px 0 2px";
◆ handleStyles()
static Monolog\Handler\BrowserConsoleHandler::handleStyles |
( |
|
$formatted | ) |
|
|
staticprivate |
Definition at line 117 of file BrowserConsoleHandler.php.
119 $args = array(self::quote(
'font-weight: normal'));
120 $format =
'%c' . $formatted;
121 preg_match_all(
'/\[\[(.*?)\]\]\{([^}]*)\}/s', $format, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
123 foreach (array_reverse($matches) as $match) {
124 $args[] = self::quote(self::handleCustomStyles($match[2][0], $match[1][0]));
125 $args[] =
'"font-weight: normal"';
128 $format = substr($format, 0, $pos) .
'%c' . $match[1][0] .
'%c' . substr($format, $pos + strlen($match[0][0]));
131 array_unshift($args, self::quote($format));
◆ quote()
static Monolog\Handler\BrowserConsoleHandler::quote |
( |
|
$arg | ) |
|
|
staticprivate |
◆ 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 60 of file BrowserConsoleHandler.php.
References $header, and $records.
64 foreach (headers_list() as
$header) {
65 if (stripos($header,
'content-type:') === 0) {
68 if (stripos($header,
'application/javascript') !==
false || stripos($header,
'text/javascript') !==
false) {
70 } elseif (stripos($header,
'text/html') ===
false) {
79 echo
'<script>' , self::generateScript() ,
'</script>';
81 echo self::generateScript();
◆ write()
Monolog\Handler\BrowserConsoleHandler::write |
( |
array |
$record | ) |
|
|
protected |
Definition at line 44 of file BrowserConsoleHandler.php.
References $records.
50 if (PHP_SAPI !==
'cli' && !self::$initialized) {
51 self::$initialized =
true;
52 register_shutdown_function(array(
'Monolog\Handler\BrowserConsoleHandler',
'send'));
◆ $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: