[GH-ISSUE #1902] Allow to specify time for log records #819

Open
opened 2026-03-04 03:00:58 +03:00 by kerem · 1 comment
Owner

Originally created by @Chi-teck on GitHub (Jul 31, 2024).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1902

That would be nice to allow users mock time for log records.

\Monolog\Logger::addRecord has an optional parameter for log timestamp. However, methods that implement Psr\Log\LoggerInterface do not have such a parameter.

I think the best way to fix this is passing optional $clock parameter to the logger constructor that implements PSR 20 interface.
Then addRecord could fetch timestamp from the clock service

Originally created by @Chi-teck on GitHub (Jul 31, 2024). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1902 That would be nice to allow users mock time for log records. `\Monolog\Logger::addRecord` has an optional parameter for log timestamp. However, methods that implement `Psr\Log\LoggerInterface` do not have such a parameter. I think the best way to fix this is passing optional `$clock` parameter to the logger constructor that implements PSR 20 interface. Then `addRecord` could fetch timestamp from the clock service
Author
Owner

@Seldaek commented on GitHub (Nov 9, 2024):

Sounds reasonable to me if you want to send a PR :)

<!-- gh-comment-id:2466215784 --> @Seldaek commented on GitHub (Nov 9, 2024): Sounds reasonable to me if you want to send a PR :)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#819
No description provided.