1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-01 19:00:20 +02:00

Fix gelf formatter keys to strip invalid characters, fixes #1927

This commit is contained in:
Jordi Boggiano
2024-12-05 15:46:00 +01:00
parent a258e4fe90
commit 595847346a
2 changed files with 3 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ namespace Monolog;
class_alias(JsonSerializableDateTimeImmutable::class, 'Monolog\DateTimeImmutable');
// @phpstan-ignore-next-line
if (false) {
/**
* @deprecated Use \Monolog\JsonSerializableDateTimeImmutable instead.

View File

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