From d234839de122875fa9db482d469b4c8d9af295de Mon Sep 17 00:00:00 2001 From: Tugdual Saunier Date: Tue, 11 Oct 2016 13:01:36 +0100 Subject: [PATCH] Make the RavenHandler picks the first highest record as main --- src/Monolog/Handler/RavenHandler.php | 2 +- tests/Monolog/Handler/RavenHandlerTest.php | 26 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Monolog/Handler/RavenHandler.php b/src/Monolog/Handler/RavenHandler.php index 0b9f3679..d3f9ed8f 100644 --- a/src/Monolog/Handler/RavenHandler.php +++ b/src/Monolog/Handler/RavenHandler.php @@ -84,7 +84,7 @@ class RavenHandler extends AbstractProcessingHandler // the record with the highest severity is the "main" one $record = array_reduce($records, function ($highest, $record) { - if ($record['level'] >= $highest['level']) { + if ($record['level'] > $highest['level']) { return $record; } diff --git a/tests/Monolog/Handler/RavenHandlerTest.php b/tests/Monolog/Handler/RavenHandlerTest.php index a7c4845f..574077df 100644 --- a/tests/Monolog/Handler/RavenHandlerTest.php +++ b/tests/Monolog/Handler/RavenHandlerTest.php @@ -195,6 +195,32 @@ class RavenHandlerTest extends TestCase $handler->handleBatch($records); } + public function testHandleBatchPicksProperMessage() + { + $records = array( + $this->getRecord(Logger::DEBUG, 'debug message 1'), + $this->getRecord(Logger::DEBUG, 'debug message 2'), + $this->getRecord(Logger::INFO, 'information 1'), + $this->getRecord(Logger::ERROR, 'error 1'), + $this->getRecord(Logger::WARNING, 'warning'), + $this->getRecord(Logger::ERROR, 'error 2'), + $this->getRecord(Logger::INFO, 'information 2'), + ); + + $logFormatter = $this->getMock('Monolog\\Formatter\\FormatterInterface'); + $logFormatter->expects($this->once())->method('formatBatch'); + + $formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface'); + $formatter->expects($this->once())->method('format')->with($this->callback(function ($record) use ($records) { + return $record['message'] == 'error 1'; + })); + + $handler = $this->getHandler($this->getRavenClient()); + $handler->setBatchFormatter($logFormatter); + $handler->setFormatter($formatter); + $handler->handleBatch($records); + } + public function testGetSetBatchFormatter() { $ravenClient = $this->getRavenClient();