mirror of
https://github.com/Seldaek/monolog.git
synced 2025-07-30 09:50:26 +02:00
Fix handling of messages with new lines
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
|
||||
|
Reference in New Issue
Block a user