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:
@@ -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) {
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user