diff --git a/src/LoggerHolder.php b/src/LoggerHolder.php index 4120e3d..eeedac9 100644 --- a/src/LoggerHolder.php +++ b/src/LoggerHolder.php @@ -4,6 +4,7 @@ use Contributte\Monolog\Exception\Logic\InvalidStateException; use Monolog\Logger; +use Monolog\LogRecord; use Nette\DI\Container; use Psr\Log\LoggerInterface; @@ -60,11 +61,21 @@ public function getLogger(): LoggerInterface $logger = clone $this->instLogger; // Write in log which class used LoggerHolder - $logger->pushProcessor(function (array $record) use ($calledBy): array { - $record['extra']['calledBy'] = $calledBy; + // Monolog >= 3.0 + if (class_exists(LogRecord::class)) { + $logger->pushProcessor(function (LogRecord $record) use ($calledBy): LogRecord { + $record->extra['calledBy'] = $calledBy; + + return $record; + }); + } else { + $logger->pushProcessor(function (array $record) use ($calledBy): array { + $record['extra']['calledBy'] = $calledBy; + + return $record; + }); + } - return $record; - }); return $logger; }