I'm trying to configure an email logging in Symfony. I followed the cookbook and it works but I have a problem with Fatal errors.
Those errors aren't logged in prod mode. I figured out that when I add Debug::enable();
to app.php, the error get logged, however I still don't get an email.
Here is the relevant configuration:
mail:
type: fingers_crossed
action_level: critical
handler: buffer
buffer:
type: buffer
handler: swift
swift:
type: swift_mailer
from_email: %error_mail_from%
to_email: %error_mail_to%
subject: %error_mail_subject%
level: debug
This is not an easy thing to log PHP Fatal Errors, because whenever the error is thrown, PHP shutdown...
However, there is a function that can be used to do a little thing just before the process shut down : register_shutdown_function
Have a look to How do I catch a PHP Fatal Error
This is how Symfony's Debug::enable();
is doing the trick. Have a look to https://github.com/symfony/Debug/blob/master/ErrorHandler.php#L118
Which Symfony version are you using?
Seems like from 2.3 there's a nice improvement that allows you to do that (logging fatal errors). Have a look at this: https://github.com/symfony/symfony/pull/6474
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With