mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-07 13:46:38 +02:00
Add millisecond precision in the LogstashFormatter
This commit is contained in:
@@ -57,8 +57,8 @@ class LogstashFormatter extends NormalizerFormatter
|
|||||||
*/
|
*/
|
||||||
public function __construct($applicationName, $systemName = null, $extraPrefix = null, $contextPrefix = 'ctxt_', $version = self::V0)
|
public function __construct($applicationName, $systemName = null, $extraPrefix = null, $contextPrefix = 'ctxt_', $version = self::V0)
|
||||||
{
|
{
|
||||||
// logstash requires a ISO 8601 format date
|
// logstash requires a ISO 8601 format date with optional millisecond precision.
|
||||||
parent::__construct('c');
|
parent::__construct('Y-m-d\TH:i:s.uP');
|
||||||
|
|
||||||
$this->systemName = $systemName ?: gethostname();
|
$this->systemName = $systemName ?: gethostname();
|
||||||
$this->applicationName = $applicationName;
|
$this->applicationName = $applicationName;
|
||||||
|
@@ -35,7 +35,7 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$message = json_decode($formatter->format($record), true);
|
$message = json_decode($formatter->format($record), true);
|
||||||
|
|
||||||
$this->assertEquals("1970-01-01T00:00:00+00:00", $message['@timestamp']);
|
$this->assertEquals("1970-01-01T00:00:00.000000+00:00", $message['@timestamp']);
|
||||||
$this->assertEquals('log', $message['@message']);
|
$this->assertEquals('log', $message['@message']);
|
||||||
$this->assertEquals('meh', $message['@fields']['channel']);
|
$this->assertEquals('meh', $message['@fields']['channel']);
|
||||||
$this->assertContains('meh', $message['@tags']);
|
$this->assertContains('meh', $message['@tags']);
|
||||||
@@ -176,7 +176,7 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$message = json_decode($formatter->format($record), true);
|
$message = json_decode($formatter->format($record), true);
|
||||||
|
|
||||||
$this->assertEquals("1970-01-01T00:00:00+00:00", $message['@timestamp']);
|
$this->assertEquals("1970-01-01T00:00:00.000000+00:00", $message['@timestamp']);
|
||||||
$this->assertEquals("1", $message['@version']);
|
$this->assertEquals("1", $message['@version']);
|
||||||
$this->assertEquals('log', $message['message']);
|
$this->assertEquals('log', $message['message']);
|
||||||
$this->assertEquals('meh', $message['channel']);
|
$this->assertEquals('meh', $message['channel']);
|
||||||
|
Reference in New Issue
Block a user