Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen:
Logging errors in Slim 3
Apr 07, 2015 @ 15:57:36

Rob Allen continues his posts looking at the use of the Slim PHP framework with this new post about logging errors.

Slim Framework 3 is being actively developed at the moment and has a number of changes in it, including the use of the Pimple DI container and an overhaul of pretty much everything else! In this post, I'm going to look at error handling. The default error handler in Slim 3 is SlimHandlersError. It's fairly simple and renders the error quite nicely, setting the HTTP status to 500. I want to log these errors via monolog.

He includes the code to first set up the Monolog logger and inject it into the dependency injection container. Then he creates a custom error handler that extends the Slim handler but overrides the __invoke method to log the message in addition to displaying it. Finally he registers the error handler into the DI container as the "errorHandler" instance so Pimple correctly knows how to throw errors.

tagged: log error slim framework monolog custom errorhandler tutorial

Link: http://akrabat.com/logging-errors-in-slim-3/


Trending Topics: