Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log Fatal errors in symfony

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
like image 980
Nemo64 Avatar asked Sep 23 '14 10:09

Nemo64


2 Answers

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

like image 128
Yann Eugoné Avatar answered Sep 29 '22 03:09

Yann Eugoné


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

like image 27
Magd Kudama Avatar answered Sep 29 '22 02:09

Magd Kudama