-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Possibility to overwrite the datetime of a record #1682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This sounds reasonable albeit kinda niche.. But adding it only to addRecord sounds ok to me as that's very low level. Would you mind rebasing on the 2.x branch tho? I think this probably should go there as well as the 3.x adoption is very low still. |
Ah well, I messed up and pushed main into your main instead of a local branch I had to do the rebase, so that closed the PR.. Anyway the code is merged in 2.x branch as 24e414c - thanks :) |
# System info - Magento 2.4.4 - PHP 8.1 # To reproduce 1. Get a setup of 2.4.4 installed 2. See that in the constraints allow for an install of `monolog/logger` at `2.7.0` 3. Try to run integration tests (https://devdocs.magento.com/guides/v2.4/test/integration/integration_test_execution.html) # The error Currently we get this error because the method signatures are different ``` PHP Fatal error: Declaration of Magento\TestFramework\ErrorLog\Logger::addRecord(int $level, string $message, array $context = []): bool must be compatible with Monolog\Logger::addRecord(int $level, string $message, array $context = [], ?Monolog\DateTimeImmutable $datetime = null): bool in dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php on line 69 ``` # Root cause This version of `monlog/logger` was tagged about an hour ago https://github.com/Seldaek/monolog/releases/tag/2.7.0 See this entry > Added $datetime parameter to Logger::addRecord as low level API to allow logging into the past or future (Seldaek/monolog#1682) Which goes along with this commit Seldaek/monolog@0ddba73#diff-1e7fd545cec457de96f5ed6bd7249ba091cd9e699b4057db15ff1e2e0364025bR297 This changes the method signature of `addRecord` like so ```diff - public function addRecord(int|Level $level, string $message, array $context = []): bool + public function addRecord(int|Level $level, string $message, array $context = [], DateTimeImmutable $datetime = null): bool ``` See the magento core logger is defined like this https://github.com/magento/magento2/blob/a8543fed035d85c667195e95f69476d51f98381b/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php#L69-L73 The method signature needs to be updated to match `monolog/logger` definition
@Henning256 @Seldaek I've found this issue in the 2.7/3.1 changelog. @Henning256 I understand your approach and solved the same issue a few weeks ago, but I decided to store 2 times: when the log record was generated and when the log record was dispatched. It's just a tip, not to forget to log both of them, it will help to debug queues of log entries and delays in the dispatching. Cheers. |
Hi and thank you. As I mentioned in my PR I implemented this feature for an async logging solution which works like this: Hope that helped someone. Cheers |
Added an optional parameter to the loggers addRecord method to overwrite the datetime of a record.
This is useful to decouple the time a record is issued and when it is persisted.
For example when caching the records to log them asynchronous.