1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-13 08:34:12 +02:00

Fix LogRecord "extra" data leaking between handlers (#1819)

Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>
This commit is contained in:
Cosmin Ardeleanu
2023-10-27 17:54:39 +03:00
committed by GitHub
parent 8ff4ab5c94
commit b0f4bf7eb7
9 changed files with 128 additions and 19 deletions

View File

@@ -11,6 +11,7 @@
namespace Monolog\Handler;
use Monolog\LogRecord;
use Monolog\Test\TestCase;
use Monolog\Level;
@@ -136,4 +137,37 @@ class WhatFailureGroupHandlerTest extends TestCase
$records = $test->getRecords();
$this->assertTrue($records[0]['extra']['foo']);
}
public function testProcessorsDoNotInterfereBetweenHandlers()
{
$t1 = new TestHandler();
$t2 = new TestHandler();
$handler = new WhatFailureGroupHandler([$t1, $t2]);
$t1->pushProcessor(function (LogRecord $record) {
$record->extra['foo'] = 'bar';
return $record;
});
$handler->handle($this->getRecord());
self::assertSame([], $t2->getRecords()[0]->extra);
}
public function testProcessorsDoNotInterfereBetweenHandlersWithBatch()
{
$t1 = new TestHandler();
$t2 = new TestHandler();
$handler = new WhatFailureGroupHandler([$t1, $t2]);
$t1->pushProcessor(function (LogRecord $record) {
$record->extra['foo'] = 'bar';
return $record;
});
$handler->handleBatch([$this->getRecord()]);
self::assertSame([], $t2->getRecords()[0]->extra);
}
}