Skip to content

Commit 5958473

Browse files
committed
Fix gelf formatter keys to strip invalid characters, fixes #1927
1 parent a258e4f commit 5958473

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/Monolog/DateTimeImmutable.php

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

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

16+
// @phpstan-ignore-next-line
1617
if (false) {
1718
/**
1819
* @deprecated Use \Monolog\JsonSerializableDateTimeImmutable instead.

src/Monolog/Formatter/GelfMessageFormatter.php

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public function format(LogRecord $record): Message
115115
}
116116

117117
foreach ($extra as $key => $val) {
118+
$key = (string) preg_replace('#[^\w\.\-]#', '-', $key);
118119
$val = \is_scalar($val) || null === $val ? $val : $this->toJson($val);
119120
$len = \strlen($this->extraPrefix . $key . $val);
120121
if ($len > $this->maxLength) {
@@ -126,6 +127,7 @@ public function format(LogRecord $record): Message
126127
}
127128

128129
foreach ($context as $key => $val) {
130+
$key = (string) preg_replace('#[^\w\.\-]#', '-', $key);
129131
$val = \is_scalar($val) || null === $val ? $val : $this->toJson($val);
130132
$len = \strlen($this->contextPrefix . $key . $val);
131133
if ($len > $this->maxLength) {

0 commit comments

Comments
 (0)