-
-
Notifications
You must be signed in to change notification settings - Fork 232
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
Existence of a custom log handler causes sending of extra email #405
Comments
Experiencing the same issue. # config/packages/prod/monolog.yaml
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: grouped
excluded_http_codes: [404, 405]
grouped:
type: group
members: [streamed, deduplicated]
streamed:
type: stream
path: '%kernel.logs_dir%/%kernel.environment%.log'
level: debug
deduplicated:
type: deduplication
handler: symfony_mailer
symfony_mailer:
type: symfony_mailer
from_email: '[email protected]'
to_email: '[email protected]'
subject: '🐾 %%message%%'
level: debug
formatter: monolog.formatter.html
content_type: text/html
console:
type: console
process_psr_3_messages: false
channels: [ "!event", "!doctrine" ]
deprecation_filter:
type: filter
handler: deprecation
max_level: info
channels: [ "php" ]
deprecation:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log" And: # config/packages/sentry.yaml
# (...)
monolog:
handlers:
sentry:
type: sentry
level: !php/const Monolog\Logger::ERROR
hub_id: Sentry\State\HubInterface
# (...)
|
The extra mail with this content is even sent if you apply the default configuration from the docs to a newly created symfony demo ( # config/packages/prod/monolog.yaml
monolog:
handlers:
main:
type: fingers_crossed
action_level: critical
handler: deduplicated
deduplicated:
type: deduplication
handler: symfony_mailer
symfony_mailer:
type: symfony_mailer
from_email: '[email protected]'
to_email: '[email protected]'
subject: 'An Error Occurred! %%message%%'
level: debug First mail contains the error message as usual, the second mail contains only this:
Tried Symfony Versions 5.2.1 / 5.2.9 / 5.3.0-RC1, running PHP 7.4.13 EDIT: I've created a corresponding Stackoverflow question |
Still no solution? |
I still see this happening for the latest and greatest, and causes double the noise/traffic when these alerts fire. |
I also encounter the exact same issue using Symfony 5.4.6, running on PHP 8.0.x. |
The issue comes from the debug log used in As this log is generated after sending of first email containig the stack trace, a second email is sent. |
Please note that with same config in "dev" env, I receive only one email, which is not the case in "prod" env. As a workaround I exclude the "mailer" channel: monolog:
handlers:
main:
type: fingers_crossed
action_level: critical
handler: grouped
channels: ["!mailer"]
grouped:
type: group
members: [streamed, deduplicated]
streamed:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
deduplicated:
type: deduplication
handler: symfony_mailer
symfony_mailer:
type: symfony_mailer
from_email: "%mailer_app_sender%"
to_email: "%mailer_team_receiver%"
subject: "An Error Occurred!"
level: debug |
If the error occurred in Command or email send async, the extra email is not sent. |
Same issue here |
same issue! |
Workaround doesn't work for me because I am doing a query to the database in the email sending flow. So I am getting this line: {"message":"Disconnecting","context":{},"level":200,"level_name":"INFO","channel":"doctrine","datetime":"2023-09-25T16:37:22.465597+00:00","extra":{"token":null,"delay":"0.20","uid":"55a1d86","memory_usage":"24 MB","memory_peak_usage":"28.58 MB"}} I cannot ignore the "doctrine" channel since error can come from there. |
I have the same issue even without a custom log handler. For some reason the workaround |
Same problem here, workaround not working... any update? |
Hey there, as a workaround try setting |
Yes IMO stop_buffering:false is good, or alternatively you can add a buffering handler before the mailer, so that the mailer handler receives all the log entries at the end of the request when the buffer handler flushes. |
I am following instructions here https://symfony.com/doc/current/logging/monolog_email.html to email critical errors.
This by itself works just fine.
But when I add a custom log handler, any error that triggers the mailer will cause a second email to be delivered as well. This second email has 2 messages in it:
The custom log handler is defined at the bottom of my monolog.yaml file like so :
It extends from AbstractProcessingHandler. The exact details of the custom error handler are not important. It has nothing to do with the mailer. I could define it with an empty write() method that does nothing. I'm actually using multiple custom log handlers, but the bug occurs if any one of them are registered.
If I remove the custom handler, an error will trigger one email as expected. If one or more custom handlers exist, I get 2 emails.
This only started happening for me since Symfony 5.2.6, previously I was on 5.2.3 and it worked as expected.
The text was updated successfully, but these errors were encountered: