From 8932d5650d46852199c2a29ec61ce444ba528f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Poirier=20Th=C3=A9or=C3=AAt?= Date: Wed, 1 Nov 2023 15:09:57 -0400 Subject: [PATCH] [Log] add resetable to decorated logger --- .../DependencyInjection/Compiler/LoggerDecoratorPass.php | 3 ++- packages/log/DecoratedLogger.php | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/framework-extra-bundle/DependencyInjection/Compiler/LoggerDecoratorPass.php b/packages/framework-extra-bundle/DependencyInjection/Compiler/LoggerDecoratorPass.php index bee1487df..5bbd0ff6e 100644 --- a/packages/framework-extra-bundle/DependencyInjection/Compiler/LoggerDecoratorPass.php +++ b/packages/framework-extra-bundle/DependencyInjection/Compiler/LoggerDecoratorPass.php @@ -96,6 +96,7 @@ private function createDecoratorLoggerDefinition(array $tag): Definition return (new Definition(DecoratedLogger::class)) ->setArgument('defaultContext', $tag) - ->setArgument('decorateMessage', $message); + ->setArgument('decorateMessage', $message) + ->addTag('kernel.reset', ['method' => 'reset']); } } diff --git a/packages/log/DecoratedLogger.php b/packages/log/DecoratedLogger.php index 737179086..2b7751368 100644 --- a/packages/log/DecoratedLogger.php +++ b/packages/log/DecoratedLogger.php @@ -2,8 +2,10 @@ namespace Draw\Component\Log; +use Monolog\ResettableInterface; use Psr\Log\LoggerInterface; use Psr\Log\LoggerTrait; +use Symfony\Contracts\Service\ResetInterface; class DecoratedLogger implements LoggerInterface { @@ -27,4 +29,11 @@ public function log($level, $message, array $context = []): void array_merge($this->defaultContext, $context) ); } + + public function reset(): void + { + if ($this->logger instanceof ResetInterface || $this->logger instanceof ResettableInterface) { + $this->logger->reset(); + } + } }