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