0

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.

Gottlieb Notschnabel
  • 9,408
  • 18
  • 74
  • 116
  • I am not sure I understand the question. Can you see the `level: debug` property on the `swift`and `streamed` groups? – yivi Aug 13 '19 at 13:52
  • 1
    The fingers crossed handler (main) will buffer all messages from the underlying loggers until a `critical` error occurs and then write all the buffered messages. Since streamed uses level `debug` it will log all messages from debug upwards, meaning for every request with a critical error it will write pretty much all entries in the log. If there is no critical error nothing is written to the log. The swift handler works similarly. Can you describe the behavior you want instead? That will make it easier to propose a useful change. – dbrumann Aug 13 '19 at 14:13
  • @dbrumann thank you for clearing that up. I edited my question to be more precise. Can I simply set `monolog.handlers.main.action_level: error` (or basically anything equal or lower than `error`), `monolog.handlers.swift.level: critical` and `monolog.handlers.streamed.level: error`? – Gottlieb Notschnabel Aug 14 '19 at 10:54
  • Yes, that could work. The `fingers_crossed`-handler might not be all that helpful, because the action level matches the logging level anyway, but I think this should produce what you are looking for. If not, feel free to append update the questions with the faulty behavior you see with the new setup – dbrumann Aug 15 '19 at 13:38

0 Answers0