I have a POST API to create a register on the database. My goal is to be able to log every 4XX request (with the response) for another team to view that list/search the data, with the option to download the request JSON sent in that call.
What’s the best way to archive that? Its just to create a logs table in the database?
3
Answers
You might want to leverage the ResponseReceived event. We can create a
LogResponseReceived
listener:In addition, you can use laravel/telescope, But that is going to log every request.
hi for this not really need to create a new table. you can use laravel logging. it’s up to you to create daily logs or a single log file.
here are some examples depending on the type of log you want to save
example
Telescope may not be a very logical choice for use in a production environment. You can find an answer to your problem with a simple middleware. If it is an endpoint that receives a lot of requests, logging to the database will not be performant enough. You can write to a different log file instead.