From 4df4b6b07a9659353b1e2b3535b7f9b9d5daaa57 Mon Sep 17 00:00:00 2001 From: Remita Amine Date: Wed, 20 Nov 2024 14:56:08 +0100 Subject: [PATCH] use Monolog's FormatterInterface format method original signature --- .../ElasticCommonSchemaFormatter.php | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Elastic/Monolog/Formatter/ElasticCommonSchemaFormatter.php b/src/Elastic/Monolog/Formatter/ElasticCommonSchemaFormatter.php index 902b8c6..0b48b8f 100644 --- a/src/Elastic/Monolog/Formatter/ElasticCommonSchemaFormatter.php +++ b/src/Elastic/Monolog/Formatter/ElasticCommonSchemaFormatter.php @@ -73,14 +73,7 @@ protected function normalize(mixed $data, int $depth = 0): mixed return parent::normalize($data, $depth); } - /** - * {@inheritdoc} - * - * @link https://www.elastic.co/guide/en/ecs/1.1/ecs-log.html - * @link https://www.elastic.co/guide/en/ecs/1.1/ecs-base.html - * @link https://www.elastic.co/guide/en/ecs/current/ecs-tracing.html - */ - public function format(LogRecord $record): string + public function formatAsArray(LogRecord $record): array { $inRecord = $this->normalize($record->toArray()); @@ -129,7 +122,19 @@ public function format(LogRecord $record): string $outRecord['tags'] = $this->normalize($this->tags); } - return $this->toJson($outRecord) . "\n"; + return $outRecord; + } + + /** + * {@inheritdoc} + * + * @link https://www.elastic.co/guide/en/ecs/1.1/ecs-log.html + * @link https://www.elastic.co/guide/en/ecs/1.1/ecs-base.html + * @link https://www.elastic.co/guide/en/ecs/current/ecs-tracing.html + */ + public function format(LogRecord $record) + { + return $this->toJson($this->formatAsArray($record)) . "\n"; } private function formatContext(array $inContext, array &$outRecord): void