How Can I Record Data Related To Http Responses In Laravel?

- 1 answer

I wanted to keep records of the http responses my server is throwing. So, for example, for each server request, I would like to record if the http response was a 1xx response, or a 2xx, 3xx and so on. At the end of the day, I would like to see, for example, that from the 1000 requests, 2% of them are a 5xx server error responses. I’m using the laravel framework.

I don’t want to redirect the responses, nor change the response messages. I just want to keep records of them. How could I achieve that? I'm not sure in which point of the laravel model I should introduce my logic. Where to intercept the final response?

Thank you for your help! :)



It seems like I have three options.

  1. (in my opinion, the best option) As mentioned by @mark-davidson, one solution is to use the server logs.
  2. One can also use middleware "after" to achieve that, as mentioned by @peterpan666.
  3. Reading the laravel documentation I just found out about the middleware "terminator", which could also be a good option, since this middleware runs only after the response is sent.