mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-05 12:47:39 +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 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.
|
||||
*/
|
||||
@@ -47,16 +43,11 @@ class WildfireFormatter extends LineFormatter
|
||||
$file = $line = '';
|
||||
if (isset($record['extra']['file'])) {
|
||||
$file = $record['extra']['file'];
|
||||
unset($record['extra']['file']);
|
||||
}
|
||||
if (isset($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
|
||||
$json = json_encode(array(
|
||||
array(
|
||||
@@ -65,7 +56,13 @@ class WildfireFormatter extends LineFormatter
|
||||
'Line' => $line,
|
||||
'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
|
||||
|
@@ -25,8 +25,8 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array(),
|
||||
'datetime' => new \DateTime,
|
||||
'context' => array('from' => 'logger'),
|
||||
'datetime' => new \DateTime("@0"),
|
||||
'extra' => array('ip' => '127.0.0.1'),
|
||||
'message' => 'log',
|
||||
);
|
||||
@@ -34,7 +34,8 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
$message = $wildfire->format($record);
|
||||
|
||||
$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
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user