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. 💪