Wednesday, October 19, 2011

Sending logs by email in Symfony2

If you want to send your logs by email in Symfony2, you have to set SwiftMailerHandler in monolog configuration:

monolog:
    handlers:
        [...]
        mail:
            type: swift_mailer
            from_email: from_address@example.com
            to_email: to_address@example.com
            subject: Error messages
            level: ERROR

Above configuration will send only error logs (one message per error). There's also NativeMailHandler which uses native PHP's mail() function.