diff --git a/src/Monolog/Handler/BufferHandler.php b/src/Monolog/Handler/BufferHandler.php index 7a590284..fbf5effa 100644 --- a/src/Monolog/Handler/BufferHandler.php +++ b/src/Monolog/Handler/BufferHandler.php @@ -27,6 +27,7 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa { use ProcessableHandlerTrait; + /** @var HandlerInterface */ protected $handler; protected $bufferSize = 0; protected $bufferLimit; @@ -137,9 +138,13 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa */ public function setFormatter(FormatterInterface $formatter): HandlerInterface { - $this->handler->setFormatter($formatter); + if ($this->handler instanceof FormattableHandlerInterface) { + $this->handler->setFormatter($formatter); - return $this; + return $this; + } + + throw new \UnexpectedValueException('The nested handler of type '.get_class($this->handler).' does not support formatters.'); } /** @@ -147,6 +152,10 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa */ public function getFormatter(): FormatterInterface { - return $this->handler->getFormatter(); + if ($this->handler instanceof FormattableHandlerInterface) { + return $this->handler->getFormatter(); + } + + throw new \UnexpectedValueException('The nested handler of type '.get_class($this->handler).' does not support formatters.'); } } diff --git a/src/Monolog/Handler/FingersCrossedHandler.php b/src/Monolog/Handler/FingersCrossedHandler.php index a63fe148..2253e71f 100644 --- a/src/Monolog/Handler/FingersCrossedHandler.php +++ b/src/Monolog/Handler/FingersCrossedHandler.php @@ -37,6 +37,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa { use ProcessableHandlerTrait; + /** @var HandlerInterface */ protected $handler; protected $activationStrategy; protected $buffering = true; diff --git a/src/Monolog/Handler/GroupHandler.php b/src/Monolog/Handler/GroupHandler.php index 51218568..a7d8a317 100644 --- a/src/Monolog/Handler/GroupHandler.php +++ b/src/Monolog/Handler/GroupHandler.php @@ -23,6 +23,7 @@ class GroupHandler extends Handler implements ProcessableHandlerInterface, Reset { use ProcessableHandlerTrait; + /** @var HandlerInterface[] */ protected $handlers; protected $bubble; @@ -116,7 +117,9 @@ class GroupHandler extends Handler implements ProcessableHandlerInterface, Reset public function setFormatter(FormatterInterface $formatter): HandlerInterface { foreach ($this->handlers as $handler) { - $handler->setFormatter($formatter); + if ($handler instanceof FormattableHandlerInterface) { + $handler->setFormatter($formatter); + } } return $this;