mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-06 05:07:36 +02:00
Add support for objects in WildfireFormatter
This commit is contained in:
@@ -18,14 +18,10 @@ use Monolog\Logger;
|
|||||||
*
|
*
|
||||||
* @author Eric Clemmons (@ericclemmons) <eric@uxdriven.com>
|
* @author Eric Clemmons (@ericclemmons) <eric@uxdriven.com>
|
||||||
* @author Christophe Coevoet <stof@notk.org>
|
* @author Christophe Coevoet <stof@notk.org>
|
||||||
|
* @author Kirill chEbba Chebunin <iam@chebba.org>
|
||||||
*/
|
*/
|
||||||
class WildfireFormatter extends LineFormatter
|
class WildfireFormatter implements FormatterInterface
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Similar to LineFormatter::SIMPLE_FORMAT, except without the "[%datetime%]"
|
|
||||||
*/
|
|
||||||
const SIMPLE_FORMAT = "%message% %context% %extra%";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates Monolog log levels to Wildfire levels.
|
* Translates Monolog log levels to Wildfire levels.
|
||||||
*/
|
*/
|
||||||
@@ -47,16 +43,11 @@ class WildfireFormatter extends LineFormatter
|
|||||||
$file = $line = '';
|
$file = $line = '';
|
||||||
if (isset($record['extra']['file'])) {
|
if (isset($record['extra']['file'])) {
|
||||||
$file = $record['extra']['file'];
|
$file = $record['extra']['file'];
|
||||||
unset($record['extra']['file']);
|
|
||||||
}
|
}
|
||||||
if (isset($record['extra']['line'])) {
|
if (isset($record['extra']['line'])) {
|
||||||
$line = $record['extra']['line'];
|
$line = $record['extra']['line'];
|
||||||
unset($record['extra']['line']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format record according with LineFormatter
|
|
||||||
$message = parent::format($record);
|
|
||||||
|
|
||||||
// Create JSON object describing the appearance of the message in the console
|
// Create JSON object describing the appearance of the message in the console
|
||||||
$json = json_encode(array(
|
$json = json_encode(array(
|
||||||
array(
|
array(
|
||||||
@@ -65,7 +56,13 @@ class WildfireFormatter extends LineFormatter
|
|||||||
'Line' => $line,
|
'Line' => $line,
|
||||||
'Label' => $record['channel'],
|
'Label' => $record['channel'],
|
||||||
),
|
),
|
||||||
$message,
|
array(
|
||||||
|
'message' => $record['message'],
|
||||||
|
// Use RFC1123 date format as default for js
|
||||||
|
'date' => $record['datetime']->format(\DateTime::RFC1123),
|
||||||
|
'context' => $record['context'],
|
||||||
|
'extra' => $record['extra']
|
||||||
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
// The message itself is a serialization of the above JSON object + it's length
|
// The message itself is a serialization of the above JSON object + it's length
|
||||||
|
@@ -25,8 +25,8 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
'level' => Logger::ERROR,
|
'level' => Logger::ERROR,
|
||||||
'level_name' => 'ERROR',
|
'level_name' => 'ERROR',
|
||||||
'channel' => 'meh',
|
'channel' => 'meh',
|
||||||
'context' => array(),
|
'context' => array('from' => 'logger'),
|
||||||
'datetime' => new \DateTime,
|
'datetime' => new \DateTime("@0"),
|
||||||
'extra' => array('ip' => '127.0.0.1'),
|
'extra' => array('ip' => '127.0.0.1'),
|
||||||
'message' => 'log',
|
'message' => 'log',
|
||||||
);
|
);
|
||||||
@@ -34,7 +34,8 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$message = $wildfire->format($record);
|
$message = $wildfire->format($record);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'84|[{"Type":"ERROR","File":"","Line":"","Label":"meh"},"log [] {\\"ip\\":\\"127.0.0.1\\"}"]|',
|
'166|[{"Type":"ERROR","File":"","Line":"","Label":"meh"},'
|
||||||
|
.'{"message":"log","date":"Thu, 01 Jan 1970 00:00:00 +0000","context":{"from":"logger"},"extra":{"ip":"127.0.0.1"}}]|',
|
||||||
$message
|
$message
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user