mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-03 19:57:41 +02:00
Added a level for the BufferHandler
This commit is contained in:
@@ -30,10 +30,12 @@ class BufferHandler extends AbstractHandler
|
||||
/**
|
||||
* @param HandlerInterface $handler Handler.
|
||||
* @param integer $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
|
||||
* @param integer $level The minimum logging level at which this handler will be triggered
|
||||
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
|
||||
*/
|
||||
public function __construct(HandlerInterface $handler, $bufferSize = 0, $bubble = false)
|
||||
public function __construct(HandlerInterface $handler, $bufferSize = 0, $level = Logger::DEBUG, $bubble = false)
|
||||
{
|
||||
parent::__construct($level, $bubble);
|
||||
$this->handler = $handler;
|
||||
$this->bufferSize = $bufferSize;
|
||||
$this->bubble = $bubble;
|
||||
@@ -44,6 +46,10 @@ class BufferHandler extends AbstractHandler
|
||||
*/
|
||||
public function handle(array $record)
|
||||
{
|
||||
if ($record['level'] < $this->level) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->buffer[] = $record;
|
||||
if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
|
||||
array_shift($this->buffer);
|
||||
|
@@ -53,4 +53,18 @@ class BufferHandlerTest extends TestCase
|
||||
$this->assertTrue($test->hasInfoRecords());
|
||||
$this->assertFalse($test->hasDebugRecords());
|
||||
}
|
||||
|
||||
public function testHandleLevel()
|
||||
{
|
||||
$test = new TestHandler();
|
||||
$handler = new BufferHandler($test, 0, Logger::INFO);
|
||||
$handler->handle($this->getRecord(Logger::DEBUG));
|
||||
$handler->handle($this->getRecord(Logger::INFO));
|
||||
$handler->handle($this->getRecord(Logger::WARNING));
|
||||
$handler->handle($this->getRecord(Logger::DEBUG));
|
||||
$handler->close();
|
||||
$this->assertTrue($test->hasWarningRecords());
|
||||
$this->assertTrue($test->hasInfoRecords());
|
||||
$this->assertFalse($test->hasDebugRecords());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user