From 8e7e8ff59d92c2bb951c4a76b8e5d793c5668ec1 Mon Sep 17 00:00:00 2001 From: mohansharma-repcard <158465165+mohansharma-repcard@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:06:00 +0530 Subject: [PATCH 1/2] Update CloudWatch.php Changed Arguent Datatype to LogRecord in Write function and Format Function --- src/Handler/CloudWatch.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Handler/CloudWatch.php b/src/Handler/CloudWatch.php index 26a1271..85c2196 100755 --- a/src/Handler/CloudWatch.php +++ b/src/Handler/CloudWatch.php @@ -161,7 +161,7 @@ public function __construct( /** * {@inheritdoc} */ - protected function write(array $record): void + protected function write(\Monolog\LogRecord $record): void { $records = $this->formatRecords($record); @@ -280,10 +280,22 @@ protected function willMessageTimestampExceedLimit(array $record): bool * @param array $entry * @return array */ - private function formatRecords(array $entry): array + private function formatRecords(\Monolog\LogRecord $entry): array { - $entries = str_split($entry['formatted'], self::EVENT_SIZE_LIMIT); - $timestamp = $entry['datetime']->format('U.u') * 1000; + // Extract the formatted message from the LogRecord + $formattedMessage = $entry->formatted; + + // If formattedMessage is not yet defined, format it here (depends on how your formatter works) + if (is_null($formattedMessage)) { + $formattedMessage = sprintf("[%s] %s: %s", $entry->datetime->format('Y-m-d H:i:s'), $entry->level->name, $entry->message); + if (!empty($entry->context)) { + $formattedMessage .= ' ' . json_encode($entry->context); + } + } + + // Split the message into chunks based on EVENT_SIZE_LIMIT + $entries = str_split($formattedMessage, self::EVENT_SIZE_LIMIT); + $timestamp = $entry->datetime->format('U.u') * 1000; $records = []; foreach ($entries as $entry) { From e73c55e81d9eb9bda056ab0d2a78c861be220ffa Mon Sep 17 00:00:00 2001 From: mohansharma-repcard <158465165+mohansharma-repcard@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:35:01 +0530 Subject: [PATCH 2/2] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a6f4ea8..6f6f10a 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ }, "require": { "php": "^7.2 || ^8", - "monolog/monolog": "^2.0", + "monolog/monolog": "^2.0 || ^3.0", "aws/aws-sdk-php": "^3.18" }, "require-dev": {