1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-29 17:30:14 +02:00

added possibility to set child handler after instantiation (#1946)

This commit is contained in:
Andrii Shevchenko
2025-03-15 14:19:21 +01:00
committed by GitHub
parent 9cfd246982
commit c8bbe52af5
2 changed files with 25 additions and 0 deletions

View File

@@ -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.');
}
public function setHandler(HandlerInterface $handler)
{
$this->handler = $handler;
}
}

View File

@@ -155,4 +155,24 @@ class BufferHandlerTest extends TestCase
$records = $test->getRecords();
$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());
}
}