From e7464a62deaf12d8f588cb2177a5dff4d510a1dc Mon Sep 17 00:00:00 2001 From: Grzesiek W Date: Sun, 16 Apr 2023 11:42:31 +0200 Subject: [PATCH] Allow to pass closure as logger configuration option --- src/PsrTarget.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/PsrTarget.php b/src/PsrTarget.php index d4849c2..e725a3c 100644 --- a/src/PsrTarget.php +++ b/src/PsrTarget.php @@ -1,8 +1,8 @@ _levels = $this->_levelMap; parent::__construct($config); } - + + /** + * Sets a logger. + * + * @param LoggerInterface $logger + */ + public function setLogger(LoggerInterface $logger) + { + $this->logger = $logger; + } + /** * @return LoggerInterface * @throws InvalidConfigException @@ -70,6 +85,11 @@ public function getLogger() if ($this->logger === null) { throw new InvalidConfigException('Logger should be configured with Psr\Log\LoggerInterface.'); } + if ($this->logger instanceof Closure) { + $loggerClosure = $this->logger; + $this->logger = $loggerClosure(); + } + return $this->logger; }