mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-23 09:36:11 +02:00
Merge pull request #426 from acdameli/master
New Handler: WhatFailureGroupHandler
This commit is contained in:
25
src/Monolog/Handler/ExceptionTestHandler.php
Normal file
25
src/Monolog/Handler/ExceptionTestHandler.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Monolog\Handler;
|
||||
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* Used for testing purposes.
|
||||
*
|
||||
* It records all records and gives you access to them for verification. It
|
||||
* throws an exception from handle and handleBatch to test the
|
||||
* WhatFailureGroupHandler Class.
|
||||
*
|
||||
* @author Craig D'Amelio <craig@damelio.ca>
|
||||
*/
|
||||
class ExceptionTestHandler extends TestHandler
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle(array $record) {
|
||||
$return = parent::handle($record);
|
||||
throw new \Exception("ExceptionTestHandler::handle");
|
||||
}
|
||||
}
|
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