From 5a6ff1516a67e386f1c2f509c4b0da394c52158f Mon Sep 17 00:00:00 2001 From: Jamie Spittal Date: Thu, 23 May 2024 09:08:55 -0700 Subject: [PATCH 1/2] Monolog Handler.php to reference Correct Log Values --- src/Logs/Monolog/src/Handler.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Logs/Monolog/src/Handler.php b/src/Logs/Monolog/src/Handler.php index d4fc86f3..d9352373 100644 --- a/src/Logs/Monolog/src/Handler.php +++ b/src/Logs/Monolog/src/Handler.php @@ -45,16 +45,15 @@ protected function getDefaultFormatter(): FormatterInterface */ protected function write($record): void { - $formatted = $record['formatted']; $logRecord = (new API\LogRecord()) ->setTimestamp((int) $record['datetime']->format('Uu') * 1000) ->setSeverityNumber(API\Map\Psr3::severityNumber($record['level_name'])) ->setSeverityText($record['level_name']) - ->setBody($formatted['message']) + ->setBody($record['message']) ; foreach (['context', 'extra'] as $key) { - if (isset($formatted[$key]) && count($formatted[$key]) > 0) { - $logRecord->setAttribute($key, $formatted[$key]); + if (isset($record[$key]) && count($record[$key]) > 0) { + $logRecord->setAttribute($key, $record[$key]); } } $this->getLogger($record['channel'])->emit($logRecord); From 939ee5897681bdf666acbe43df8b8f4b747e17a5 Mon Sep 17 00:00:00 2001 From: Jamie Spittal Date: Thu, 30 May 2024 10:53:05 -0700 Subject: [PATCH 2/2] Adding JsonFormatter support to Monolog Handler --- src/Logs/Monolog/src/Handler.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Logs/Monolog/src/Handler.php b/src/Logs/Monolog/src/Handler.php index d9352373..d718eb21 100644 --- a/src/Logs/Monolog/src/Handler.php +++ b/src/Logs/Monolog/src/Handler.php @@ -45,15 +45,18 @@ protected function getDefaultFormatter(): FormatterInterface */ protected function write($record): void { + $formatted = ($this->getFormatter() instanceof JsonFormatter) + ? json_decode($record['formatted'], true) + : $record['formatted']; $logRecord = (new API\LogRecord()) ->setTimestamp((int) $record['datetime']->format('Uu') * 1000) ->setSeverityNumber(API\Map\Psr3::severityNumber($record['level_name'])) ->setSeverityText($record['level_name']) - ->setBody($record['message']) + ->setBody($formatted['message']) ; foreach (['context', 'extra'] as $key) { - if (isset($record[$key]) && count($record[$key]) > 0) { - $logRecord->setAttribute($key, $record[$key]); + if (isset($formatted[$key]) && count($formatted[$key]) > 0) { + $logRecord->setAttribute($key, $formatted[$key]); } } $this->getLogger($record['channel'])->emit($logRecord);