1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-02-24 15:02:28 +01:00

Tweaked the GroupHandler to make it handle a record only when needed

This commit is contained in:
Christophe Coevoet 2011-05-11 23:59:45 +02:00
parent 0defabb726
commit 6c9946aca8

View File

@ -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;
}