Handler sending logs to browser's javascript console with no browser extension required.
More...
|
| close () |
|
| reset () |
|
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
- bool 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
- bool
} 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 () |
|
| reset () |
|
|
static | send () |
| Convert records to javascript console commands and send it to the browser. More...
|
|
static | resetStatic () |
| 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 228 of file BrowserConsoleHandler.php.
230 $args = func_get_args();
231 $method = array_shift($args);
233 return static::call_array($method, $args);
◆ call_array()
static Monolog\Handler\BrowserConsoleHandler::call_array |
( |
|
$method, |
|
|
array |
$args |
|
) |
| |
|
staticprivate |
◆ close()
Monolog\Handler\BrowserConsoleHandler::close |
( |
| ) |
|
◆ dump()
static Monolog\Handler\BrowserConsoleHandler::dump |
( |
|
$title, |
|
|
array |
$dict |
|
) |
| |
|
staticprivate |
Definition at line 204 of file BrowserConsoleHandler.php.
References $key, and $title.
207 $dict = array_filter($dict);
211 $script[] = static::call(
'log', static::quote(
'%c%s'), static::quote(
'font-weight: bold'), static::quote(
$title));
212 foreach ($dict as
$key => $value) {
213 $value = json_encode($value);
215 $value = static::quote(
'');
217 $script[] = static::call(
'log', static::quote(
'%s: %o'), static::quote(
$key), $value);
◆ generateScript()
static Monolog\Handler\BrowserConsoleHandler::generateScript |
( |
| ) |
|
|
staticprivate |
Definition at line 143 of file BrowserConsoleHandler.php.
References $context, and $records.
147 $context = static::dump(
'Context', $record[
'context']);
148 $extra = static::dump(
'Extra', $record[
'extra']);
150 if (empty(
$context) && empty($extra)) {
151 $script[] = static::call_array(
'log', static::handleStyles($record[
'formatted']));
153 $script = array_merge($script,
154 array(static::call_array(
'groupCollapsed', static::handleStyles($record[
'formatted']))),
157 array(static::call(
'groupEnd'))
162 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 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 123 of file BrowserConsoleHandler.php.
References $header.
126 foreach (headers_list() as
$header) {
127 if (stripos($header,
'content-type:') === 0) {
130 if (stripos($header,
'application/javascript') !==
false || stripos($header,
'text/javascript') !==
false) {
133 if (stripos($header,
'text/html') ===
false) {
◆ handleCustomStyles()
static Monolog\Handler\BrowserConsoleHandler::handleCustomStyles |
( |
|
$style, |
|
|
|
$string |
|
) |
| |
|
staticprivate |
Definition at line 184 of file BrowserConsoleHandler.php.
References $m, and $style.
186 static $colors = array(
'blue',
'green',
'red',
'magenta',
'orange',
'black',
'grey');
187 static $labels = array();
189 return preg_replace_callback(
'/macro\s*:(.*?)(?:;|$)/',
function (
$m) use ($string, &$colors, &$labels) {
190 if (trim(
$m[1]) ===
'autolabel') {
192 if (!isset($labels[$string])) {
193 $labels[$string] = $colors[count($labels) % count($colors)];
195 $color = $labels[$string];
197 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 165 of file BrowserConsoleHandler.php.
References $format.
167 $args = array(static::quote(
'font-weight: normal'));
169 preg_match_all(
'/\[\[(.*?)\]\]\{([^}]*)\}/s',
$format, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
171 foreach (array_reverse($matches) as $match) {
172 $args[] = static::quote(static::handleCustomStyles($match[2][0], $match[1][0]));
173 $args[] =
'"font-weight: normal"';
176 $format = substr(
$format, 0, $pos) .
'%c' . $match[1][0] .
'%c' . substr(
$format, $pos + strlen($match[0][0]));
179 array_unshift($args, static::quote(
$format));
◆ quote()
static Monolog\Handler\BrowserConsoleHandler::quote |
( |
|
$arg | ) |
|
|
staticprivate |
◆ registerShutdownFunction()
Monolog\Handler\BrowserConsoleHandler::registerShutdownFunction |
( |
| ) |
|
|
protected |
◆ reset()
Monolog\Handler\BrowserConsoleHandler::reset |
( |
| ) |
|
◆ resetStatic()
static Monolog\Handler\BrowserConsoleHandler::resetStatic |
( |
| ) |
|
|
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 = static::getResponseFormat();
68 static::writeOutput(
'<script>' . static::generateScript() .
'</script>');
70 static::writeOutput(static::generateScript());
72 static::resetStatic();
◆ 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: