mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-01 10:50:21 +02:00
Merge branch '1.x'
This commit is contained in:
@@ -62,6 +62,7 @@ class FluentdFormatter implements FormatterInterface
|
||||
|
||||
$message = [
|
||||
'message' => $record['message'],
|
||||
'context' => $record['context'],
|
||||
'extra' => $record['extra'],
|
||||
];
|
||||
|
||||
|
44
src/Monolog/Handler/BrowserConsoleHandler.php
Normal file → Executable file
44
src/Monolog/Handler/BrowserConsoleHandler.php
Normal file → Executable file
@@ -44,11 +44,11 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
|
||||
protected function write(array $record)
|
||||
{
|
||||
// Accumulate records
|
||||
self::$records[] = $record;
|
||||
static::$records[] = $record;
|
||||
|
||||
// Register shutdown handler if not already done
|
||||
if (!self::$initialized) {
|
||||
self::$initialized = true;
|
||||
if (!static::$initialized) {
|
||||
static::$initialized = true;
|
||||
$this->registerShutdownFunction();
|
||||
}
|
||||
}
|
||||
@@ -59,18 +59,18 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
|
||||
*/
|
||||
public static function send()
|
||||
{
|
||||
$format = self::getResponseFormat();
|
||||
$format = static::getResponseFormat();
|
||||
if ($format === 'unknown') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (count(self::$records)) {
|
||||
if (count(static::$records)) {
|
||||
if ($format === 'html') {
|
||||
self::writeOutput('<script>' . self::generateScript() . '</script>');
|
||||
static::writeOutput('<script>' . static::generateScript() . '</script>');
|
||||
} elseif ($format === 'js') {
|
||||
self::writeOutput(self::generateScript());
|
||||
static::writeOutput(static::generateScript());
|
||||
}
|
||||
self::reset();
|
||||
static::reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
|
||||
*/
|
||||
public static function reset()
|
||||
{
|
||||
self::$records = [];
|
||||
static::$records = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,18 +134,18 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
|
||||
private static function generateScript()
|
||||
{
|
||||
$script = [];
|
||||
foreach (self::$records as $record) {
|
||||
$context = self::dump('Context', $record['context']);
|
||||
$extra = self::dump('Extra', $record['extra']);
|
||||
foreach (static::$records as $record) {
|
||||
$context = static::dump('Context', $record['context']);
|
||||
$extra = static::dump('Extra', $record['extra']);
|
||||
|
||||
if (empty($context) && empty($extra)) {
|
||||
$script[] = self::call_array('log', self::handleStyles($record['formatted']));
|
||||
$script[] = static::call_array('log', static::handleStyles($record['formatted']));
|
||||
} else {
|
||||
$script = array_merge($script,
|
||||
[self::call_array('groupCollapsed', self::handleStyles($record['formatted']))],
|
||||
[static::call_array('groupCollapsed', static::handleStyles($record['formatted']))],
|
||||
$context,
|
||||
$extra,
|
||||
[self::call('groupEnd')]
|
||||
[static::call('groupEnd')]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -155,19 +155,19 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
|
||||
|
||||
private static function handleStyles($formatted)
|
||||
{
|
||||
$args = [self::quote('font-weight: normal')];
|
||||
$args = [static::quote('font-weight: normal')];
|
||||
$format = '%c' . $formatted;
|
||||
preg_match_all('/\[\[(.*?)\]\]\{([^}]*)\}/s', $format, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
|
||||
|
||||
foreach (array_reverse($matches) as $match) {
|
||||
$args[] = self::quote(self::handleCustomStyles($match[2][0], $match[1][0]));
|
||||
$args[] = static::quote(static::handleCustomStyles($match[2][0], $match[1][0]));
|
||||
$args[] = '"font-weight: normal"';
|
||||
|
||||
$pos = $match[0][1];
|
||||
$format = substr($format, 0, $pos) . '%c' . $match[1][0] . '%c' . substr($format, $pos + strlen($match[0][0]));
|
||||
}
|
||||
|
||||
array_unshift($args, self::quote($format));
|
||||
array_unshift($args, static::quote($format));
|
||||
|
||||
return $args;
|
||||
}
|
||||
@@ -199,13 +199,13 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
|
||||
if (empty($dict)) {
|
||||
return $script;
|
||||
}
|
||||
$script[] = self::call('log', self::quote('%c%s'), self::quote('font-weight: bold'), self::quote($title));
|
||||
$script[] = static::call('log', static::quote('%c%s'), static::quote('font-weight: bold'), static::quote($title));
|
||||
foreach ($dict as $key => $value) {
|
||||
$value = json_encode($value);
|
||||
if (empty($value)) {
|
||||
$value = self::quote('');
|
||||
$value = static::quote('');
|
||||
}
|
||||
$script[] = self::call('log', self::quote('%s: %o'), self::quote($key), $value);
|
||||
$script[] = static::call('log', static::quote('%s: %o'), static::quote($key), $value);
|
||||
}
|
||||
|
||||
return $script;
|
||||
@@ -221,7 +221,7 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
|
||||
$args = func_get_args();
|
||||
$method = array_shift($args);
|
||||
|
||||
return self::call_array($method, $args);
|
||||
return static::call_array($method, $args);
|
||||
}
|
||||
|
||||
private static function call_array($method, array $args)
|
||||
|
@@ -70,6 +70,11 @@ class SlackWebhookHandler extends AbstractProcessingHandler
|
||||
return $this->slackRecord;
|
||||
}
|
||||
|
||||
public function getWebhookUrl()
|
||||
{
|
||||
return $this->webhookUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
|
@@ -40,7 +40,7 @@ class FluentdFormatterTest extends TestCase
|
||||
|
||||
$formatter = new FluentdFormatter();
|
||||
$this->assertEquals(
|
||||
'["test",0,{"message":"test","extra":[],"level":300,"level_name":"WARNING"}]',
|
||||
'["test",0,{"message":"test","context":[],"extra":[],"level":300,"level_name":"WARNING"}]',
|
||||
$formatter->format($record)
|
||||
);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class FluentdFormatterTest extends TestCase
|
||||
|
||||
$formatter = new FluentdFormatter(true);
|
||||
$this->assertEquals(
|
||||
'["test.error",0,{"message":"test","extra":[]}]',
|
||||
'["test.error",0,{"message":"test","context":[],"extra":[]}]',
|
||||
$formatter->format($record)
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user