diff --git a/src/Monolog/Formatter/GelfMessageFormatter.php b/src/Monolog/Formatter/GelfMessageFormatter.php index d169e1b6..12a3b0a3 100644 --- a/src/Monolog/Formatter/GelfMessageFormatter.php +++ b/src/Monolog/Formatter/GelfMessageFormatter.php @@ -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) { diff --git a/tests/Monolog/Formatter/GelfMessageFormatterTest.php b/tests/Monolog/Formatter/GelfMessageFormatterTest.php index bd10d374..a882e76c 100644 --- a/tests/Monolog/Formatter/GelfMessageFormatterTest.php +++ b/tests/Monolog/Formatter/GelfMessageFormatterTest.php @@ -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);