The Symfony documentation on "How to Configure Monolog to Email Errors" is describing how to combine two different logging targets (last example, scroll to bottom of doc).
# config/packages/prod/monolog.yaml
monolog:
handlers:
main:
type: fingers_crossed
action_level: critical
handler: grouped
grouped:
type: group
members: [streamed, deduplicated]
streamed:
type: stream
path: '%kernel.logs_dir%/%kernel.environment%.log'
level: debug
deduplicated:
type: deduplication
handler: swift
swift:
type: swift_mailer
from_email: 'error@example.com'
to_email: 'error@example.com'
subject: 'An Error Occurred! %%message%%'
level: debug
formatter: monolog.formatter.html
content_type: text/html
But in this example, the monolog.handlers.main.action_level
defines the level of errors. How can I use different levels –in this case– for the stream and for the mailing logger?
In detail, I want to log all 400 and 500 errors (action_level error
) to the stream, but I only want 500 errors (action_level critical
) to be sent by mail.