1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-11 23:54:04 +02:00

JsonFormatter: add option to ignore empty context and extra fields

Similar to efe572cb10.
This commit is contained in:
Gabriel Caruso
2020-04-01 05:03:52 +02:00
parent 13ee5dabda
commit 6038dcb21c
2 changed files with 33 additions and 3 deletions

View File

@@ -295,4 +295,23 @@ class JsonFormatterTest extends TestCase
$this->assertCount(1001, $res['context'][0]);
$this->assertEquals('Over 1000 items (2000 total), aborting normalization', $res['context'][0]['...']);
}
public function testEmptyContextAndExtraFieldsCanBeIgnored()
{
$formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_JSON, true, true);
$record = $formatter->format(array(
'level' => 100,
'level_name' => 'DEBUG',
'channel' => 'test',
'message' => 'Testing',
'context' => array(),
'extra' => array(),
));
$this->assertSame(
'{"level":100,"level_name":"DEBUG","channel":"test","message":"Testing"}'."\n",
$record
);
}
}