diff --git a/src/Monolog/Handler/DeduplicationHandler.php b/src/Monolog/Handler/DeduplicationHandler.php index 740ed5ae..7778c22a 100644 --- a/src/Monolog/Handler/DeduplicationHandler.php +++ b/src/Monolog/Handler/DeduplicationHandler.php @@ -114,12 +114,12 @@ class DeduplicationHandler extends BufferHandler $yesterday = time() - 86400; $timestampValidity = $record['datetime']->getTimestamp() - $this->time; - $line = $record['level_name'] . ':' . $record['message']; + $expectedMessage = preg_replace('{[\r\n].*}', '', $record['message']); for ($i = count($store) - 1; $i >= 0; $i--) { list($timestamp, $level, $message) = explode(':', $store[$i], 3); - if ($level === $record['level_name'] && $message === $record['message'] && $timestamp > $timestampValidity) { + if ($level === $record['level_name'] && $message === $expectedMessage && $timestamp > $timestampValidity) { return true; } @@ -164,6 +164,6 @@ class DeduplicationHandler extends BufferHandler private function appendRecord(array $record) { - file_put_contents($this->deduplicationStore, $record['datetime']->getTimestamp() . ':' . $record['level_name'] . ':' . $record['message'] . "\n", FILE_APPEND); + file_put_contents($this->deduplicationStore, $record['datetime']->getTimestamp() . ':' . $record['level_name'] . ':' . preg_replace('{[\r\n].*}', '', $record['message']) . "\n", FILE_APPEND); } } diff --git a/tests/Monolog/Handler/DeduplicationHandlerTest.php b/tests/Monolog/Handler/DeduplicationHandlerTest.php index 7ca8dd99..e2aff868 100644 --- a/tests/Monolog/Handler/DeduplicationHandlerTest.php +++ b/tests/Monolog/Handler/DeduplicationHandlerTest.php @@ -46,7 +46,7 @@ class DeduplicationHandlerTest extends TestCase $handler = new DeduplicationHandler($test, sys_get_temp_dir().'/monolog_dedup.log', 0); $handler->handle($this->getRecord(Logger::ERROR, 'Foo:bar')); - $handler->handle($this->getRecord(Logger::CRITICAL)); + $handler->handle($this->getRecord(Logger::CRITICAL, "Foo\nbar")); $handler->flush(); @@ -67,7 +67,7 @@ class DeduplicationHandlerTest extends TestCase $handler = new DeduplicationHandler($test, sys_get_temp_dir().'/monolog_dedup.log', 0); $handler->handle($this->getRecord(Logger::ERROR, 'Foo:bar')); - $handler->handle($this->getRecord(Logger::CRITICAL)); + $handler->handle($this->getRecord(Logger::CRITICAL, "Foo\nbar")); $handler->flush();