mirror of
https://github.com/Seldaek/monolog.git
synced 2026-04-25 23:55:56 +03:00
[GH-ISSUE #1433] DeduplicationHandler passes duplicated entries to the next handler #601
Labels
No labels
Bug
Documentation
Feature
Needs Work
Support
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/monolog#601
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @wskorodecki on GitHub (Feb 26, 2020).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1433
Monolog version: 1.25.3
I'm using DeduplicationHandler to avoid duplicated deprecation messages but it still passes all entries via
$this->handler->handleBatch($this->buffer);to the next handler (RotatingFileHandler). I think this is because of the following line:$passthru = $passthru || !$this->isDuplicate($record);The first call to isDuplicate() method results in
falsebecause the duplication store file does not exists yet, so$passthrubecomestrueand will never befalseagain.I'm not sure but I think the code should be modified a bit to something like this:
My config:
@Seldaek commented on GitHub (May 11, 2020):
The deduplication is only happening/effective between requests, within one request duplicate messages will still be all sent through. So on the first request yes the file is created and it passes everything through to nested handler, then on subsequent requests it should stop sending any logs unless there is a new deprecation.
@Seldaek commented on GitHub (May 11, 2020):
So IMO not a bug unless I misunderstand what you are saying.. At least it seems to work for me as described.
@M0nik commented on GitHub (May 14, 2020):
I have the same problem. Within one request duplicate messages should not be sent.
@Seldaek commented on GitHub (May 14, 2020):
What's the use case you are trying to achieve exactly?
@M0nik commented on GitHub (May 14, 2020):
I use async PHP (
walkor/Workerman). Messages accumulate over time. The flush method is called by the timer (e.g. every 10 seconds). By the time the flush is called, many identical messages may have accumulated.@Seldaek commented on GitHub (May 14, 2020):
Ok for long running processes running many jobs, it is recommended to call
$logger->reset()in between every job. It essentially makes Monolog behave as if a request ended and a new one started. Buffers get flushed etc, it avoids memory leaks and generally speaking makes job processing behave closer to a per-request execution model.@M0nik commented on GitHub (May 14, 2020):
This does not solve the current problem, as within the same iteration, there can still be many identical messages.
@Seldaek commented on GitHub (May 14, 2020):
Yeah maybe that's still a feature request then for DeduplicationHandler to have an option to deduplicate even within its own buffer.. Feel free to send a PR if you can add that.
@puleeno commented on GitHub (Aug 8, 2020):
I have the same problem. The log entry is duplicated on version 2.x
@Tobion commented on GitHub (Jan 14, 2021):
This is really a problem. Messages should be deduplicated within it's buffer as there can be thousands of deprecation messages in a worker or even a single cli command / web request. E.g. https://github.com/doctrine/orm/pull/7901 triggered ALOT of deprecations for us which overwhelmed graylog.
Another problem is that the
deduplicationhandler does not support specifying thebuffer_sizeand$flushOnOverflow. This means the deduplcation can grow endlessly and is a memory leak. Other buffered handlers like FingersCrossed support this option.@Tobion commented on GitHub (Jan 14, 2021):
Another problem is that the deduplicationStore file can grow indefinitely:
$timeas I would expect).@Seldaek commented on GitHub (Jan 14, 2021):
@Tobion this was a quick fix solution which served a purpose already, but it's definitely not perfect. PRs are definitely welcome at least to deduplicate within the buffer and allow setting buffer size etc. The deduplicationStore issues you describe I'm not sure if they're fixable within a reasonable amount of added complexity, but if so that'd also be good to fix.
@bravik commented on GitHub (Nov 5, 2021):
Have a graphql API. When I query some problematic field in collection item, it will trigger same error for each collection element but will not stop execution. So I'll have numerous same log messages triggered inside 1 request. Which I tried to avoid by using deduplication filter. But looking in the code I came to same colcusion as author of this issue.