Error Handling & Logging

From Tomahawk 1.2.0, there is an Exception Middleware ( Tomahawk\HttpKernel\Middleware\ExceptionMiddleware)
which is used for catching and logging errors as well as rendering responses for 404 and all 50x errors.

Configuration

Error Templates

In app/config there should be a file called error.php. If there isn't create it and add the following to it:

Here you can configure what templates are used for 404 and 50x errors. If you used Tomahawk before version 1.2.0 you will have to add these in.

Error Logging

Tomahawk uses Monolog for logging errors. It has quite a simple setup. There is one handler which logs to a daily file.

In app/config there should be a file called monolog.php. If there isn't create it and add the following to it:

Here you can edit where the logs are written too as well as the name of the log file. The RotatingFileHandler will add the date to this filename.

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 $this->container->get('logger').