1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-07 05:36:45 +02:00

Add millisecond precision in the LogstashFormatter

This commit is contained in:
Albert Casademont
2013-11-11 15:50:38 +01:00
parent 43f97bb5af
commit 899f7f52e5
2 changed files with 4 additions and 4 deletions

View File

@@ -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;

View File

@@ -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']);