Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Formatter/SimpleFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public function format(LogMessage $event): string
$context['levelName'] = $event->level()->name();
$context['message'] = $event->formattedMessage();
foreach ($context as $name => $value) {
if (is_array($value) || is_object($value)) {
$value = json_encode($value);
}
$output = str_replace("%$name%", (string) $value, $output);
}
return $output;
Expand Down
15 changes: 15 additions & 0 deletions test/Formatter/SimpleFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,19 @@ public function testFormatConvertsNonStringContextValues(): void
// Should convert boolean to string
$this->assertStringContainsString('Value: 1', $output);
}

public function testFormatWithArrayContextValueDoesNotWarn(): void
{
$formatter = new SimpleFormatter('Extra: %extra%');
$message = new LogMessage(
$this->level,
'test',
['extra' => ['foo' => 'bar']]
);
$message->formatMessage([]);

$output = $formatter->format($message);

$this->assertStringContainsString('Extra: {"foo":"bar"}', $output);
}
}
Loading