1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-30 01:40:30 +02:00

Fix gelf message formatter failing to handle context/extra numeric keys, fixes #1932

This commit is contained in:
Jordi Boggiano
2025-03-16 14:03:31 +01:00
parent 7ca003e6ae
commit 467e764fb6
2 changed files with 3 additions and 3 deletions

View File

@@ -115,7 +115,7 @@ class GelfMessageFormatter extends NormalizerFormatter
}
foreach ($extra as $key => $val) {
$key = (string) preg_replace('#[^\w\.\-]#', '-', $key);
$key = (string) preg_replace('#[^\w.-]#', '-', (string) $key);
$val = \is_scalar($val) || null === $val ? $val : $this->toJson($val);
$len = \strlen($this->extraPrefix . $key . $val);
if ($len > $this->maxLength) {
@@ -127,7 +127,7 @@ class GelfMessageFormatter extends NormalizerFormatter
}
foreach ($context as $key => $val) {
$key = (string) preg_replace('#[^\w\.\-]#', '-', $key);
$key = (string) preg_replace('#[^\w.-]#', '-', (string) $key);
$val = \is_scalar($val) || null === $val ? $val : $this->toJson($val);
$len = \strlen($this->contextPrefix . $key . $val);
if ($len > $this->maxLength) {

View File

@@ -67,7 +67,7 @@ class GelfMessageFormatterTest extends MonologTestCase
channel: 'meh',
context: ['from' => 'logger'],
datetime: new \DateTimeImmutable("@0"),
extra: ['file' => 'test', 'line' => 14],
extra: ['file' => 'test', 'line' => 14, 0 => 'foo'],
);
$message = $formatter->format($record);