1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-22 17:16:18 +02:00

Json formatter should always format context/extra as an object, fixes #1028

This commit is contained in:
Jordi Boggiano
2018-06-09 17:02:23 +02:00
parent c150186e4f
commit c7b12a7497
3 changed files with 15 additions and 5 deletions

View File

@@ -64,7 +64,15 @@ class JsonFormatter extends NormalizerFormatter
*/
public function format(array $record): string
{
return $this->toJson($this->normalize($record), true) . ($this->appendNewline ? "\n" : '');
$normalized = $this->normalize($record);
if (isset($normalized['context']) && $normalized['context'] === []) {
$normalized['context'] = new \stdClass;
}
if (isset($normalized['extra']) && $normalized['extra'] === []) {
$normalized['extra'] = new \stdClass;
}
return $this->toJson($normalized, true) . ($this->appendNewline ? "\n" : '');
}
/**