Duplicated log during an error
shavounet opened this issue · comments
Description
In our project we noticed that when an error occurs, we have 2 logs
- one with the
route
and a complete error message - one with less data (mostly useless, all data is already in the 1st)
With some analysis, I found that the fos/rest-bundle that is installed, have an event listener on kernel.exception
that create a new response (thank to this Symfony component) that triggers a second time kernel.response
.
[2022-08-31 17:27:31] event.DEBUG: Notified event "kernel.response" to listener "M6Web\Bundle\LogBridgeBundle\EventDispatcher\LogRequestListener::onKernelTerminate".
[2022-08-31 17:27:31] event.DEBUG: Notified event "kernel.exception" to listener "M6Web\Bundle\LogBridgeBundle\EventDispatcher\LogExceptionListener::onKernelException".
[2022-08-31 17:27:31] event.DEBUG: Notified event "kernel.exception" to listener "FOS\RestBundle\EventListener\ExceptionListener::onKernelException".
[2022-08-31 17:27:31] event.DEBUG: Listener "FOS\RestBundle\EventListener\ExceptionListener::onKernelException" stopped propagation of the event "kernel.exception".
[2022-08-31 17:27:31] event.DEBUG: Notified event "kernel.response" to listener "M6Web\Bundle\LogBridgeBundle\EventDispatcher\LogRequestListener::onKernelTerminate".
This is not exclusive to the FOS Rest Bundle, kernel.response
can be triggered every time a response is calculated.
A proposed solution would be to change the listener to properly listen on kernel.terminate
, which is only triggered once.
What do you think ?
Well, it's not the same log, but I agree one seems useless.
Imho, we need to think about what we want. I would say that we want to log the final response, so terminate could be great if we have access to the response with it's response code.