mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-07 05:36:45 +02:00
Group handler that ignores failures
This allows a group handler which on a single handler failing will continue and allow subsequent handlers to record the event.
This commit is contained in:
48
src/Monolog/Handler/WhatFailureGroupHandler.php
Normal file
48
src/Monolog/Handler/WhatFailureGroupHandler.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Monolog\Handler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forwards records to multiple handlers suppressing failures of each handler
|
||||||
|
* and continuing through to give every handler a chance to succeed.
|
||||||
|
*
|
||||||
|
* @author Craig D'Amelio <craig@damelio.ca>
|
||||||
|
*/
|
||||||
|
class WhatFailureGroupHandler extends GroupHandler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function handle(array $record)
|
||||||
|
{
|
||||||
|
if ($this->processors) {
|
||||||
|
foreach ($this->processors as $processor) {
|
||||||
|
$record = call_user_func($processor, $record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->handlers as $handler) {
|
||||||
|
try {
|
||||||
|
$handler->handle($record);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// What failure?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false === $this->bubble;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function handleBatch(array $records)
|
||||||
|
{
|
||||||
|
foreach ($this->handlers as $handler) {
|
||||||
|
try {
|
||||||
|
$handler->handleBatch($records);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// What failure?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user