Dev - consultant - artisan

Qualité, amélioration continue, agilité, professionnalisme.

Un besoin ? Un projet ? Écrivez moi !

Don’t miss 500 internal error anymore with symfony and monolog

Spread the love

Sometimes I read my server logs … Like some people read the newspaper, in fact server logs are like the app newspaper 🙂

Every morning I am reading my logwatch email.

But I can miss errors, and even if I see them, it is the next day in my logs email, and it is really BAD

The solution is simple, use monolog to send you errors directly

https://symfony.com/doc/current/logging/monolog_email.html

My configuration is (config_prod.yml):

monolog:
    handlers:
        main:
            type:   stream
            path:   "%kernel.logs_dir%/%kernel.environment%.log"
            level:  error
        mail:
            type:         fingers_crossed
            # 500 errors are logged at the critical level
            action_level: critical
             handler:      deduplicated
        deduplicated:
            type:    deduplication
            handler: swift
        swift:
            type:       swift_mailer
            from_email: 'email@myserv.myserv'
            to_email:   'mymorningemail@myserv.myserv'
            subject:    'You have to work ! An Error Occurred! %%message%%'
            level:      debug
            formatter:  monolog.formatter.html
            content_type: text/html

 

 

Leave a reply

Your email address will not be published.