mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-02 19:27:37 +02:00
added possibility to set child handler after instantiation (#1946)
This commit is contained in:
committed by
GitHub
parent
9cfd246982
commit
c8bbe52af5
@@ -162,4 +162,9 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa
|
|||||||
|
|
||||||
throw new \UnexpectedValueException('The nested handler of type '.\get_class($this->handler).' does not support formatters.');
|
throw new \UnexpectedValueException('The nested handler of type '.\get_class($this->handler).' does not support formatters.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setHandler(HandlerInterface $handler)
|
||||||
|
{
|
||||||
|
$this->handler = $handler;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -155,4 +155,24 @@ class BufferHandlerTest extends TestCase
|
|||||||
$records = $test->getRecords();
|
$records = $test->getRecords();
|
||||||
$this->assertTrue($records[0]['extra']['foo']);
|
$this->assertTrue($records[0]['extra']['foo']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSetHandler()
|
||||||
|
{
|
||||||
|
$testOriginal = new TestHandler();
|
||||||
|
$handler = new BufferHandler($testOriginal);
|
||||||
|
$handler->handle($this->getRecord(Level::Info));
|
||||||
|
|
||||||
|
$testNew = new TestHandler();
|
||||||
|
$handler->setHandler($testNew);
|
||||||
|
|
||||||
|
$handler->handle($this->getRecord(Level::Debug));
|
||||||
|
|
||||||
|
$handler->close();
|
||||||
|
|
||||||
|
$this->assertFalse($testOriginal->hasInfoRecords());
|
||||||
|
$this->assertFalse($testOriginal->hasDebugRecords());
|
||||||
|
$this->assertTrue($testNew->hasInfoRecords());
|
||||||
|
$this->assertTrue($testNew->hasDebugRecords());
|
||||||
|
$this->assertCount(2, $testNew->getRecords());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user