diff --git a/src/Monolog/Formatter/WildfireFormatter.php b/src/Monolog/Formatter/WildfireFormatter.php index 3bdda52d..c1821d56 100644 --- a/src/Monolog/Formatter/WildfireFormatter.php +++ b/src/Monolog/Formatter/WildfireFormatter.php @@ -18,14 +18,10 @@ use Monolog\Logger; * * @author Eric Clemmons (@ericclemmons) * @author Christophe Coevoet + * @author Kirill chEbba Chebunin */ -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 diff --git a/tests/Monolog/Formatter/WildfireFormatterTest.php b/tests/Monolog/Formatter/WildfireFormatterTest.php index 8213a69b..c314a0af 100644 --- a/tests/Monolog/Formatter/WildfireFormatterTest.php +++ b/tests/Monolog/Formatter/WildfireFormatterTest.php @@ -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 ); }