From 162c30768d66e375ee0bd92b1411c65938914d98 Mon Sep 17 00:00:00 2001 From: Reinier Kip Date: Mon, 11 May 2015 13:26:40 +0200 Subject: [PATCH] Allow PSR-3 passthru level in FingersCrossedHandler. --- src/Monolog/Handler/FingersCrossedHandler.php | 5 ++++- .../Monolog/Handler/FingersCrossedHandlerTest.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Monolog/Handler/FingersCrossedHandler.php b/src/Monolog/Handler/FingersCrossedHandler.php index a81c9e64..30a85dd6 100644 --- a/src/Monolog/Handler/FingersCrossedHandler.php +++ b/src/Monolog/Handler/FingersCrossedHandler.php @@ -61,7 +61,10 @@ class FingersCrossedHandler extends AbstractHandler $this->bufferSize = $bufferSize; $this->bubble = $bubble; $this->stopBuffering = $stopBuffering; - $this->passthruLevel = $passthruLevel; + + if ($passthruLevel !== null) { + $this->passthruLevel = Logger::toMonologLevel($passthruLevel); + } if (!$this->handler instanceof HandlerInterface && !is_callable($this->handler)) { throw new \RuntimeException("The given handler (".json_encode($this->handler).") is not a callable nor a Monolog\Handler\HandlerInterface object"); diff --git a/tests/Monolog/Handler/FingersCrossedHandlerTest.php b/tests/Monolog/Handler/FingersCrossedHandlerTest.php index a3d350d5..8e31e9b8 100644 --- a/tests/Monolog/Handler/FingersCrossedHandlerTest.php +++ b/tests/Monolog/Handler/FingersCrossedHandlerTest.php @@ -15,6 +15,7 @@ use Monolog\TestCase; use Monolog\Logger; use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy; use Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy; +use Psr\Log\LogLevel; class FingersCrossedHandlerTest extends TestCase { @@ -237,4 +238,18 @@ class FingersCrossedHandlerTest extends TestCase $this->assertFalse($test->hasDebugRecords()); $this->assertTrue($test->hasInfoRecords()); } + + /** + * @covers Monolog\Handler\FingersCrossedHandler::close + */ + public function testPsrLevelPassthruOnClose() + { + $test = new TestHandler(); + $handler = new FingersCrossedHandler($test, new ErrorLevelActivationStrategy(Logger::WARNING), 0, true, true, LogLevel::INFO); + $handler->handle($this->getRecord(Logger::DEBUG)); + $handler->handle($this->getRecord(Logger::INFO)); + $handler->close(); + $this->assertFalse($test->hasDebugRecords()); + $this->assertTrue($test->hasInfoRecords()); + } }