Email Error reporting for your Symfony projects

After launching a couple of projects, I’ve quickly realized that most users will simply stop using your project when confronted with a bug or an exception. So you have to always be on top of any bug that happens, fix it ASAP, apologize to your user and notify them that you’ve fixed the issue. That’s the only way to get them back.

In this tutorial, I’ll show you how to configure email reports with Monolog on production and set up a debug message.

Configure Monolog

First, make sure to have Monolog installed (check your composer.json.) Then we need to tell monolog to send us email alerts for errors.

Make sure to adapt the email address.

Setup an event listener

Now, simply setting up Monolog should work and you’ll get email alerts whenever an exception is thrown. But sometimes you might need more debug context to better understand the error.
To achieve this, we can hook into the EXCEPTION kernel event and add whatever debug message we want. Here is an example of how to do that:

Conclusion

By getting the errors to your inbox as soon as they happen in production, hopefully you’ll be able to fix them faster, make your users happier and your projects more successful.  💪

  • niepi

    great post, we use the same setup with our live application. The only thing missing for us was that when you have multiple servers, then you don’t know on which server the error happened, so I have overwrote the template to output the hostname of the server

  • Tiago Brito

    I still remember when I implemented this 4 years ago: https://github.com/Seldaek/monolog/pull/275
    Thanks for your article. I still think this monolog formatter is very useful for small applications and not everyone know it.