public function format(array $record)
{
// Retrieve the line and file if set and remove them from the formatted extra
$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(
'Type' => $this->logLevels[$record['level']],
'File' => $file,
'Line' => $line,
'Label' => $record['channel'],
),
$message,
));
// The message itself is a serialization of the above JSON object + it's length
return sprintf(
'%s|%s|',
strlen($json),
$json
);
}
/** * @covers Monolog\Formatter\WildfireFormatter::format */ public function testFormatWithoutContext() { $wildfire = new WildfireFormatter(); $record = array('level' => Logger::ERROR, 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array(), 'datetime' => new \DateTime("@0"), 'extra' => array(), 'message' => 'log'); $message = $wildfire->format($record); $this->assertEquals('58|[{"Type":"ERROR","File":"","Line":"","Label":"meh"},"log"]|', $message); }