From 69fb2aa1c16dc532b0a9f8d704cfe51407e3b604 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 2 Jul 2016 14:48:22 +0100 Subject: [PATCH] Fix GroupHandler::handleBatch when the handler has processors, fixes #814 --- src/Monolog/Handler/GroupHandler.php | 10 ++++++++++ tests/Monolog/Handler/GroupHandlerTest.php | 23 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/Monolog/Handler/GroupHandler.php b/src/Monolog/Handler/GroupHandler.php index 48e7b8e5..663f5a92 100644 --- a/src/Monolog/Handler/GroupHandler.php +++ b/src/Monolog/Handler/GroupHandler.php @@ -75,6 +75,16 @@ class GroupHandler extends AbstractHandler */ public function handleBatch(array $records) { + if ($this->processors) { + $processed = array(); + foreach ($records as $record) { + foreach ($this->processors as $processor) { + $processed[] = call_user_func($processor, $record); + } + } + $records = $processed; + } + foreach ($this->handlers as $handler) { $handler->handleBatch($records); } diff --git a/tests/Monolog/Handler/GroupHandlerTest.php b/tests/Monolog/Handler/GroupHandlerTest.php index c6298a6e..a1b86176 100644 --- a/tests/Monolog/Handler/GroupHandlerTest.php +++ b/tests/Monolog/Handler/GroupHandlerTest.php @@ -86,4 +86,27 @@ class GroupHandlerTest extends TestCase $records = $test->getRecords(); $this->assertTrue($records[0]['extra']['foo']); } + + /** + * @covers Monolog\Handler\GroupHandler::handle + */ + public function testHandleBatchUsesProcessors() + { + $testHandlers = array(new TestHandler(), new TestHandler()); + $handler = new GroupHandler($testHandlers); + $handler->pushProcessor(function ($record) { + $record['extra']['foo'] = true; + + return $record; + }); + $handler->handleBatch(array($this->getRecord(Logger::DEBUG), $this->getRecord(Logger::INFO))); + foreach ($testHandlers as $test) { + $this->assertTrue($test->hasDebugRecords()); + $this->assertTrue($test->hasInfoRecords()); + $this->assertTrue(count($test->getRecords()) === 2); + $records = $test->getRecords(); + $this->assertTrue($records[0]['extra']['foo']); + $this->assertTrue($records[1]['extra']['foo']); + } + } }