mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-05 04:37:38 +02:00
Added the possibility to configure whether the FingersCrossedHandler should continue to buffer after being triggered or not
The change is BC as the default is to stop buffering.
This commit is contained in:
@@ -29,19 +29,22 @@ class FingersCrossedHandler extends AbstractHandler
|
|||||||
protected $buffering = true;
|
protected $buffering = true;
|
||||||
protected $bufferSize;
|
protected $bufferSize;
|
||||||
protected $buffer = array();
|
protected $buffer = array();
|
||||||
|
protected $stopBuffering;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param callback|HandlerInterface $handler Handler or factory callback($record, $fingersCrossedHandler).
|
* @param callback|HandlerInterface $handler Handler or factory callback($record, $fingersCrossedHandler).
|
||||||
* @param int $actionLevel The minimum logging level at which this handler will be triggered
|
* @param int $actionLevel The minimum logging level at which this handler will be triggered
|
||||||
* @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
|
* @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
|
||||||
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
|
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
|
||||||
|
* @param Boolean $stopBuffering Whether the handler should stop buffering after being triggered (default true)
|
||||||
*/
|
*/
|
||||||
public function __construct($handler, $actionLevel = Logger::WARNING, $bufferSize = 0, $bubble = false)
|
public function __construct($handler, $actionLevel = Logger::WARNING, $bufferSize = 0, $bubble = false, $stopBuffering = true)
|
||||||
{
|
{
|
||||||
$this->handler = $handler;
|
$this->handler = $handler;
|
||||||
$this->actionLevel = $actionLevel;
|
$this->actionLevel = $actionLevel;
|
||||||
$this->bufferSize = $bufferSize;
|
$this->bufferSize = $bufferSize;
|
||||||
$this->bubble = $bubble;
|
$this->bubble = $bubble;
|
||||||
|
$this->stopBuffering = $stopBuffering;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,7 +58,9 @@ class FingersCrossedHandler extends AbstractHandler
|
|||||||
array_shift($this->buffer);
|
array_shift($this->buffer);
|
||||||
}
|
}
|
||||||
if ($record['level'] >= $this->actionLevel) {
|
if ($record['level'] >= $this->actionLevel) {
|
||||||
$this->buffering = false;
|
if ($this->stopBuffering) {
|
||||||
|
$this->buffering = false;
|
||||||
|
}
|
||||||
if (!$this->handler instanceof HandlerInterface) {
|
if (!$this->handler instanceof HandlerInterface) {
|
||||||
$this->handler = call_user_func($this->handler, $record, $this);
|
$this->handler = call_user_func($this->handler, $record, $this);
|
||||||
}
|
}
|
||||||
|
@@ -52,6 +52,18 @@ class FingersCrossedHandlerTest extends TestCase
|
|||||||
$this->assertFalse($test->hasInfoRecords());
|
$this->assertFalse($test->hasInfoRecords());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testHandleRestartBufferingAfterBeingTriggered()
|
||||||
|
{
|
||||||
|
$test = new TestHandler();
|
||||||
|
$handler = new FingersCrossedHandler($test, Logger::WARNING, 0, false, false);
|
||||||
|
$handler->handle($this->getRecord(Logger::DEBUG));
|
||||||
|
$handler->handle($this->getRecord(Logger::WARNING));
|
||||||
|
$handler->handle($this->getRecord(Logger::INFO));
|
||||||
|
$this->assertTrue($test->hasWarningRecords());
|
||||||
|
$this->assertTrue($test->hasDebugRecords());
|
||||||
|
$this->assertFalse($test->hasInfoRecords());
|
||||||
|
}
|
||||||
|
|
||||||
public function testHandleBufferLimit()
|
public function testHandleBufferLimit()
|
||||||
{
|
{
|
||||||
$test = new TestHandler();
|
$test = new TestHandler();
|
||||||
|
Reference in New Issue
Block a user