Skip to content

Commit

Permalink
Fix gelf formatter keys to strip invalid characters, fixes #1927
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Dec 5, 2024
1 parent a258e4f commit 5958473
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Monolog/DateTimeImmutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class_alias(JsonSerializableDateTimeImmutable::class, 'Monolog\DateTimeImmutable');

// @phpstan-ignore-next-line
if (false) {
/**
* @deprecated Use \Monolog\JsonSerializableDateTimeImmutable instead.
Expand Down
2 changes: 2 additions & 0 deletions src/Monolog/Formatter/GelfMessageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public function format(LogRecord $record): Message
}

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) {
Expand All @@ -126,6 +127,7 @@ public function format(LogRecord $record): Message
}

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) {
Expand Down

0 comments on commit 5958473

Please sign in to comment.