From 6c9946aca876697cb5ddaea59cbb6a34d15f98b0 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Wed, 11 May 2011 23:59:45 +0200 Subject: [PATCH] Tweaked the GroupHandler to make it handle a record only when needed --- src/Monolog/Handler/GroupHandler.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Monolog/Handler/GroupHandler.php b/src/Monolog/Handler/GroupHandler.php index 0d054431..d2737fa4 100644 --- a/src/Monolog/Handler/GroupHandler.php +++ b/src/Monolog/Handler/GroupHandler.php @@ -11,8 +11,6 @@ namespace Monolog\Handler; -use Monolog\Logger; - /** * Forwards records to multiple handlers * @@ -28,6 +26,12 @@ class GroupHandler extends AbstractHandler */ public function __construct(array $handlers, $bubble = false) { + foreach ($handlers as $handler) { + if (!$handler instanceof HandlerInterface) { + throw new \InvalidArgumentException('The first argument of the GroupHandler must be an array of HandlerInterface instances.'); + } + } + $this->handlers = $handlers; $this->bubble = $bubble; } @@ -37,7 +41,13 @@ class GroupHandler extends AbstractHandler */ public function isHandling(array $record) { - return true; + foreach ($this->handlers as $handler) { + if ($handler->isHandling($record)) { + return true; + } + } + + return false; } /** @@ -48,6 +58,7 @@ class GroupHandler extends AbstractHandler foreach ($this->handlers as $handler) { $handler->handle($record); } + return false === $this->bubble; }