4
votes

I am trying to create pretty error pages for my application by following this cookbook article. Sometimes a bug slips in, which causes the application to return a single line: 503 Service Unavailable. It would make my life a whole lot easier if only I could see the underlying error or exception thrown. Switching over to the development environment doesn't help either as the error templates are only used in production.

I figured out that I needed to add TwigBundle to assetic's configuration to use javascript and css assets. Problems like this are really hard to debug in the production environment.

Setting the debug mode to true in my front controller doesn't help, since production error templates get replaced by development templates.

EDIT

Thanks to Mike Purcell I managed to retrieve the errors provided. I got

Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException' in /[snip]/app/cache/prod/appprodUrlMatcher.php:669

Turns out the framework should be handling the exception, but in the case of a possible error inside the error Twig template, it just decides to throw a 503 error.

How do I turn on error reporting for the production environment in a Symfony2 application?

I'm tired of guessing what's wrong and clearing the cache. What is the best way to debug Twig's error templates in production?

2
This is exactly why the php error_log file exists.Mike Purcell
@MikePurcell indeed. I'd be happy to have the errors going to error_log. Unfortunately the log is empty.kgilden
You can configure your php error log handling via php.ini, specifically the error_log entry. us3.php.net/manual/en/errorfunc.configuration.php#ini.error-log . You can check your current setting by running this via cli: php -i | fgrep -i error_logMike Purcell
@MikePurcell Thanks for the tip. There's no related entries. I grepped through the framework code looking for error_reporting and display_errors. Found the code suppressing errors and commented it out. Success! I'm getting a ResourceNotFoundException which in turn should trigger rendering the error template, but the exception is not caught.kgilden
I would update your question with the newly found issue as I am sure some Symfonians (v2) will be able to assist you further.Mike Purcell

2 Answers

3
votes

The best way to see what errors are being thrown in production is to configure Monolog to email the errors too you or alternatively to a file.

Have a look at the Symfony2 Cookbook on emailing logs http://symfony.com/doc/master/cookbook/logging/monolog_email.html

To make the error pages look nicer have a look at this cookbook entry on how to do that http://symfony.com/doc/master/cookbook/controller/error_pages.html

0
votes

There are open source tools specifically built for error reporting like Sentry, which has a native Symfony client.

disclaimer: I work for Sentry