Symfony2 Monolog Settings for registering email and files

I want to configure Symfony2 to send email for critical errors, but only log error level errors. Will there be the following settings?

 monolog: handlers: main: type: fingers_crossed action_level: error handler: grouped grouped: type: group members: [filelog, mail] # log all errors to file filelog: type: fingers_crossed action_level: error handler: nested_stream nested_stream: type: stream path: "%kernel.logs_dir%/%kernel.environment%.log" level: debug # send me an email when we have a critical error mail: type: fingers_crossed action_level: critical handler: buffered buffered: type: buffer handler: swift swift: type: swift_mailer from_email: %mailer_sender% to_email: %error_email% subject: "[FeedStream Error]" level: debug 

I saw: http://symfony.com/doc/current/cookbook/logging/monolog_email.html But it doesn't handle error at all, which is the case when I still need the logs (but not email). I was sure that my configuration would work, but I do not know enough about the monologue settings. Please let me know if this is correct or if there is a better way.

+6
source share
1 answer

Below is my monologue configuration. This is confirmed by the work of sending critical errors, as well as registering "errors" and higher to a file. I also split the various channels for file sharing. Other channels seem to cause errors much less than a "request", so it makes sense to split them into production for me. Understand that this is not your question, but I hope this helps someone else; It can satisfy all requirements.

 monolog: handlers: main: level: error type: stream path: "%kernel.logs_dir%/%kernel.environment%_remaining.log" channels: ["!doctrine", "!request", "!security"] request: type: fingers_crossed handler: requests excluded_404s: - ^/phpmyadmin requests: type: group members: [request_critical, request_error] request_critical: level: critical type: stream path: "%kernel.logs_dir%/%kernel.environment%_request_critical.log" channels: [request] request_error: level: error type: stream path: "%kernel.logs_dir%/%kernel.environment%_request.log" channels: [request] doctrine: level: error type: stream path: "%kernel.logs_dir%/%kernel.environment%_doctrine.log" channels: [doctrine] security: level: error type: stream path: "%kernel.logs_dir%/%kernel.environment%_security.log" channels: [security] mail: type: fingers_crossed action_level: critical handler: buffered buffered: type: buffer handler: swift swift: type: swift_mailer from_email: aj.cerqueti@example.com to_email: aj.cerqueti@example.com subject: A critical error occurred 
+7
source

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


All Articles