mirror of
https://github.com/Seldaek/monolog.git
synced 2025-07-31 10:20:14 +02:00
Only close handles that have been opened by the StreamHandler, fixes #764
This commit is contained in:
@@ -59,7 +59,7 @@ class StreamHandler extends AbstractProcessingHandler
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
if (is_resource($this->stream)) {
|
||||
if ($this->url && is_resource($this->stream)) {
|
||||
fclose($this->stream);
|
||||
}
|
||||
$this->stream = null;
|
||||
|
@@ -35,10 +35,26 @@ class StreamHandlerTest extends TestCase
|
||||
/**
|
||||
* @covers Monolog\Handler\StreamHandler::close
|
||||
*/
|
||||
public function testClose()
|
||||
public function testCloseKeepsExternalHandlersOpen()
|
||||
{
|
||||
$handle = fopen('php://memory', 'a+');
|
||||
$handler = new StreamHandler($handle);
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$handler->close();
|
||||
$this->assertTrue(is_resource($handle));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Handler\StreamHandler::close
|
||||
*/
|
||||
public function testClose()
|
||||
{
|
||||
$handler = new StreamHandler('php://memory');
|
||||
$handler->handle($this->getRecord(Logger::WARNING, 'test'));
|
||||
$streamProp = new \ReflectionProperty('Monolog\Handler\StreamHandler', 'stream');
|
||||
$streamProp->setAccessible(true);
|
||||
$handle = $streamProp->getValue($handler);
|
||||
|
||||
$this->assertTrue(is_resource($handle));
|
||||
$handler->close();
|
||||
$this->assertFalse(is_resource($handle));
|
||||
|
Reference in New Issue
Block a user