From 0d72125865aa0df5770cdf3cb12000c8490dc091 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 23 Apr 2014 09:20:04 +0200 Subject: [PATCH] Lazy-initialize the buffer handler, fixes #359 --- src/Monolog/Handler/BufferHandler.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Monolog/Handler/BufferHandler.php b/src/Monolog/Handler/BufferHandler.php index 6a802733..183d239a 100644 --- a/src/Monolog/Handler/BufferHandler.php +++ b/src/Monolog/Handler/BufferHandler.php @@ -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();