What You’ll Learn
Why every production app needs a request log
Assigning a unique X-Request-ID to every request
Logging method, URL, user, duration, and response status
Persisting to a request_logs table for DB cross-referencing
Writing the log after the response is sent, so logging never slows down or breaks a request
Excluding health check and static routes
Why You Need a Request Log
When a user reports “something went wrong around 2pm yesterday”, you need to answer: which request, with which data, made by which user, that took how long, and got what response?
Without a request log: you dig through exception logs, guess at timing, and can’t confirm which user triggered what.
With a request log: one query on the request_logs table gives you the complete picture — and the request_id connects it to every model change and exception that happened during that request.
The request_logs Table
Schema :: create ( 'request_logs' , function ( Blueprint $table ) : void { $table -> id ( ) ; $table -> string…