1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-10 23:24:02 +02:00

Lazy-initialize the buffer handler, fixes #359

This commit is contained in:
Jordi Boggiano
2014-04-23 09:20:04 +02:00
parent 97f79f7ed3
commit 0d72125865

View File

@@ -28,6 +28,7 @@ class BufferHandler extends AbstractHandler
protected $bufferLimit;
protected $flushOnOverflow;
protected $buffer = array();
protected $initialized = false;
/**
* @param HandlerInterface $handler Handler.
@@ -42,9 +43,6 @@ class BufferHandler extends AbstractHandler
$this->handler = $handler;
$this->bufferLimit = (int) $bufferLimit;
$this->flushOnOverflow = $flushOnOverflow;
// __destructor() doesn't get called on Fatal errors
register_shutdown_function(array($this, 'close'));
}
/**
@@ -56,6 +54,12 @@ class BufferHandler extends AbstractHandler
return false;
}
if (!$this->initialized) {
// __destructor() doesn't get called on Fatal errors
register_shutdown_function(array($this, 'close'));
$this->initialized = true;
}
if ($this->bufferLimit > 0 && $this->bufferSize === $this->bufferLimit) {
if ($this->flushOnOverflow) {
$this->flush();