Error Handling & Logging

From Tomahawk 2.0.0 it ships with a ErrorHandlerBundle which is used for catching and logging errors as well as rendering responses for 404 and all 50x errors.

Creating Error Templates

In app/Resources/ErrorHandlerBundle/views there are 3 templates:

  • error500.twig
  • error404.twig
  • exception.twig

You can create a template with the name errorXXX.php for a specific HTTP Status Code.

If a template doesn't exist for a specific HTTP Status code then exception.twig will be used.

Error Logging

Tomahawk uses Monolog for logging errors. It has quite a simple setup.

In app/config there will be a file called logging.php.

Tomahawk allows you to use either the stream, rotating_file or fingers_crossed handlers.

Custom Logging Handler

You can write your own handler by implementing Monolog\Handler\HandlerInterface, adding the handler to the service container and adding it to the logging config as follows:

Using the Logger

The easiest way to use the logger is to just add the following parameter to the construct method of your Controller Psr\Log\LoggerInterface and it will get injected in through the Service Container.

You can also get into out of the container by doing $container->get('logger').