Log Fatal errors in symfony

I am trying to set up email logging in Symfony. I followed the cookbook and it works, but I have a problem with fatal errors.

These errors are not logged in prod mode. I realized that when I add Debug::enable(); in app.php, the error is logged, however I still do not receive the letter.

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 
+5
source share
3 answers

It is not easy to register PHP Fatal Errors, because whenever an error occurs, turn off PHP ... However, there is a function that can be used to do a small thing just before the process ends: register_shutdown_function

Look at How Can I Get Fatal PHP Error

Here's how the Symfony Debug::enable(); . Take a look at https://github.com/symfony/Debug/blob/master/ErrorHandler.php#L118

+2
source

What version of symfony are you using?

There seems to be a nice improvement from 2.3 that allows you to do this (logging fatal errors). Take a look at this: https://github.com/symfony/symfony/pull/6474

+1
source

I had the same problem (fatal erros registered in production but not emailed) and I managed to get it working by adding to my config_prod.php:

 services: mydebug.debug_handlers_listener: class: Symfony\Component\HttpKernel\EventListener\DebugHandlersListener arguments: - { 0:"@http_kernel", 1:'terminateWithException'} tags: - { name: kernel.event_subscriber } 

I found that such a service is defined in \vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Resources\config\debug.xml , but not in debug_prod.xml .

With a call to terminateWithException it works fine in my application.

0
source

Source: https://habr.com/ru/post/1203205/


All Articles