Symfony2 Monolog Settings for email and file logging
monolog, symfony
Solution
The following is my production monolog config. This is confirmed working sending critical errors, whilst logging 'error' level and above to file. I've also split out the different channels to separate files. The other channels seem to produce errors far less than 'request', so it makes sense to split them out in production for me. Realise that's not your question, but hope it helps someone else; this can pared back to fit most 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
Problem
I want to setup Symfony2 to send me an email for `critical` errors, but just log `error` level errors. Will the following settings do that? ``` 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 a case where I still want logs (but no email). I was pretty sure my config would work, but I don't know enough about the monolog settings. Please let me know if this is correct or if there is a better way.