monolog-bundle: Existence of a custom log handler causes sending of extra email
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:
- DEBUG Email transport “Symfony\Component\Mailer\Transport\Smtp\SmtpTransport” stopping
- DEBUG Email transport “Symfony\Component\Mailer\Transport\Smtp\SmtpTransport” stopped
The custom log handler is defined at the bottom of my monolog.yaml file like so :
new_relic_notifier:
level: critical
type: service
id: Shared\Symfony\LogHandler\NewRelicNotifier
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.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 9
- Comments: 15 (4 by maintainers)
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:
I have the same issue even without a custom log handler. For some reason the workaround
channels: ["!mailer"]does not work for me. I still get two emails, one of them clearly from the mailer channel.The extra mail with this content is even sent if you apply the default configuration from the docs to a newly created symfony demo (
symfony new --demo) in production mode.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
https://stackoverflow.com/questions/67702288/monolog-send-error-logs-by-mail-causes-an-extra-mail-for-every-error-sent