Skip to content

Commit

Permalink
[Log] add resetable to decorated logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Nov 1, 2023
1 parent 70afdb0 commit 8932d56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
9 changes: 9 additions & 0 deletions packages/log/DecoratedLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
}
}
}

0 comments on commit 8932d56

Please sign in to comment.