1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-30 01:40:30 +02:00

Added $datetime parameter to addRecord method to optionally log into the past/future

This commit is contained in:
henning
2022-06-07 16:13:46 +02:00
committed by Jordi Boggiano
parent 8ac56aa42b
commit 24e414c993
2 changed files with 29 additions and 6 deletions

View File

@@ -739,6 +739,28 @@ class LoggerTest extends \PHPUnit\Framework\TestCase
$this->assertNotSame($uid1, $processorUid1->getUid());
$this->assertNotSame($uid2, $processorUid2->getUid());
}
/**
* @covers Logger::addRecord
*/
public function testLogWithDateTime()
{
foreach ([true, false] as $microseconds) {
$logger = new Logger(__METHOD__);
$loggingHandler = new LoggingHandler($logger);
$testHandler = new TestHandler();
$logger->pushHandler($loggingHandler);
$logger->pushHandler($testHandler);
$datetime = (new DateTimeImmutable($microseconds))->modify('2022-03-04 05:06:07');
$logger->addRecord(Logger::DEBUG, 'test', [], $datetime);
list($record) = $testHandler->getRecords();
$this->assertEquals($datetime->format('Y-m-d H:i:s'), $record['datetime']->format('Y-m-d H:i:s'));
}
}
}
class LoggingHandler implements HandlerInterface