1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-07 13:46:38 +02:00

Remove duplicate call to BufferHandler::close, fixes #386

This commit is contained in:
Jordi Boggiano
2014-07-28 22:08:10 +02:00
parent ac3f343f2d
commit 16afa5ac26
2 changed files with 20 additions and 4 deletions

View File

@@ -91,6 +91,13 @@ class BufferHandler extends AbstractHandler
$this->clear(); $this->clear();
} }
public function __destruct()
{
// suppress the parent behavior since we already have register_shutdown_function()
// to call close(), and the reference contained there will prevent this from being
// GC'd until the end of the request
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@@ -16,6 +16,8 @@ use Monolog\Logger;
class BufferHandlerTest extends TestCase class BufferHandlerTest extends TestCase
{ {
private $shutdownCheckHandler;
/** /**
* @covers Monolog\Handler\BufferHandler::__construct * @covers Monolog\Handler\BufferHandler::__construct
* @covers Monolog\Handler\BufferHandler::handle * @covers Monolog\Handler\BufferHandler::handle
@@ -38,15 +40,22 @@ class BufferHandlerTest extends TestCase
* @covers Monolog\Handler\BufferHandler::close * @covers Monolog\Handler\BufferHandler::close
* @covers Monolog\Handler\BufferHandler::flush * @covers Monolog\Handler\BufferHandler::flush
*/ */
public function testDestructPropagatesRecords() public function testPropagatesRecordsAtEndOfRequest()
{ {
$test = new TestHandler(); $test = new TestHandler();
$handler = new BufferHandler($test); $handler = new BufferHandler($test);
$handler->handle($this->getRecord(Logger::WARNING)); $handler->handle($this->getRecord(Logger::WARNING));
$handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::DEBUG));
$handler->__destruct(); $this->shutdownCheckHandler = $test;
$this->assertTrue($test->hasWarningRecords()); register_shutdown_function(array($this, 'checkPropagation'));
$this->assertTrue($test->hasDebugRecords()); }
public function checkPropagation()
{
if (!$this->shutdownCheckHandler->hasWarningRecords() || !$this->shutdownCheckHandler->hasDebugRecords()) {
echo '!!! BufferHandlerTest::testPropagatesRecordsAtEndOfRequest failed to verify that the messages have been propagated' . PHP_EOL;
exit(1);
}
} }
/** /**