Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
20 changes: 16 additions & 4 deletions src/Handler/CloudWatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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