mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-09 14:46:46 +02:00
Tweaked the GroupHandler to make it handle a record only when needed
This commit is contained in:
@@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
namespace Monolog\Handler;
|
namespace Monolog\Handler;
|
||||||
|
|
||||||
use Monolog\Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forwards records to multiple handlers
|
* Forwards records to multiple handlers
|
||||||
*
|
*
|
||||||
@@ -28,6 +26,12 @@ class GroupHandler extends AbstractHandler
|
|||||||
*/
|
*/
|
||||||
public function __construct(array $handlers, $bubble = false)
|
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->handlers = $handlers;
|
||||||
$this->bubble = $bubble;
|
$this->bubble = $bubble;
|
||||||
}
|
}
|
||||||
@@ -37,8 +41,14 @@ class GroupHandler extends AbstractHandler
|
|||||||
*/
|
*/
|
||||||
public function isHandling(array $record)
|
public function isHandling(array $record)
|
||||||
{
|
{
|
||||||
|
foreach ($this->handlers as $handler) {
|
||||||
|
if ($handler->isHandling($record)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -48,6 +58,7 @@ class GroupHandler extends AbstractHandler
|
|||||||
foreach ($this->handlers as $handler) {
|
foreach ($this->handlers as $handler) {
|
||||||
$handler->handle($record);
|
$handler->handle($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false === $this->bubble;
|
return false === $this->bubble;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user