37        return new LineFormatter(
'[[%channel%]]{macro: autolabel} [[%level_name%]]{font-weight: bold} %message%');
 
   43    protected function write(array $record)
 
   49        if (!self::$initialized) {
 
   50            self::$initialized = 
true;
 
   59    public static function send()
 
   89        if (PHP_SAPI !== 
'cli') {
 
   90            register_shutdown_function(array(
'Monolog\Handler\BrowserConsoleHandler', 
'send'));
 
  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) {
 
  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);";
 
  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));
 
  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";
 
  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);
 
  207            $script[] = 
self::call(
'log', self::quote(
'%s: %o'), self::quote(
$key), $value);
 
  215        return '"' . addcslashes($arg, 
"\"\n\\") . 
'"';
 
  220        $args = func_get_args();
 
  221        $method = array_shift($args);
 
  228        return 'c.' . $method . 
'(' . implode(
', ', $args) . 
');';
 
An exception for terminatinating execution or to throw for unit testing.
Base Handler class providing the Handler structure.
Handler sending logs to browser's javascript console with no browser extension required.
static call_array($method, array $args)
static reset()
Forget all logged records.
static dump($title, array $dict)
getDefaultFormatter()
Gets the default formatter.FormatterInterface
registerShutdownFunction()
Wrapper for register_shutdown_function to allow overriding.
static handleCustomStyles($style, $string)
static handleStyles($formatted)
write(array $record)
Writes the record down to the log of the implementing handler.void
static writeOutput($str)
Wrapper for echo to allow overriding.
static send()
Convert records to javascript console commands and send it to the browser.
static getResponseFormat()
Checks the format of the response.