I want to be alerted when bad things happen in my Symfony2 app. Right now I just look for ERROR in the logs. Unfortunately, “HTTP 404 – file not found” (NotFoundHttpException) gets logged as an error, as does “HTTP 403 – forbidden” (AccessDeniedHttpException).
This doesn’t warrant an error; at the most these should be warnings. How can I make these log at a less severe level?
Example error:
[2012-07-02 16:58:21] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /foo" (uncaught exception) at /home/user/Symfony2_v2.0.12/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/RouterListener.php line 83 [] []
I found something that works. The Symfony2 internals doc on the kernel.exeption event mention that a response can be set on the event, and the GetResponseForExceptionEvent docs say
I cobbled together a listener that appears to do just what I want: