diff --git a/src/App/Processors/NullStringProcessor.php b/src/App/Processors/NullStringProcessor.php index 1ad36e2..3837055 100644 --- a/src/App/Processors/NullStringProcessor.php +++ b/src/App/Processors/NullStringProcessor.php @@ -4,22 +4,26 @@ namespace Asseco\Gelf\App\Processors; +use Monolog\LogRecord; + class NullStringProcessor { /** * Transform a "NULL" string record into a null value. * - * @param array $record - * @return array + * @param LogRecord $record + * @return LogRecord */ - public function __invoke(array $record): array + public function __invoke(LogRecord $record): LogRecord { - foreach ($record['context'] as $key => $value) { + $context = $record->context; + + foreach ($context as $key => $value) { if (is_string($value) && strtoupper($value) === 'NULL') { - $record['context'][$key] = null; + $context[$key] = null; } } - return $record; + return $record->with(context: $context); } } diff --git a/src/App/Processors/RenameIdFieldProcessor.php b/src/App/Processors/RenameIdFieldProcessor.php index f1be768..c08c8ac 100644 --- a/src/App/Processors/RenameIdFieldProcessor.php +++ b/src/App/Processors/RenameIdFieldProcessor.php @@ -4,6 +4,8 @@ namespace Asseco\Gelf\App\Processors; +use Monolog\LogRecord; + class RenameIdFieldProcessor { /** @@ -11,16 +13,18 @@ class RenameIdFieldProcessor * * @see https://github.com/hedii/laravel-gelf-logger/issues/33 */ - public function __invoke(array $record): array + public function __invoke(LogRecord $record): LogRecord { - foreach ($record['context'] as $key => $value) { + $context = $record->context; + + foreach ($context as $key => $value) { if ($key === 'id' && !array_key_exists('_id', $record['context'])) { - unset($record['context']['id']); + unset($context['id']); - $record['context']['_id'] = $value; + $context['_id'] = $value; } } - return $record; + return $record->with(context: $context); } }