I am not sure if laravel generate's an unique id for each request, but what about combining the timestamp, route and ip address (should be pretty unique right?).
Create unique request ID and bind to app
Hi,
I'm working on improving the logging in my app. Basically, I want to be able to see all logs associated with a single request.
In Laravel 5.3 is there an existing unique ID that is generated for each request? If not, is there a recommended way to create a unique ID and then bind it to the app in a way that I can access anywhere?
Also, if you have any tips about inserting this ID into every log (without having to do so manually) let me know!
Thanks!
Just in case someone comes across this answer years later, the Laravel 10 documentation describes how to do this very simply: https://laravel.com/docs/10.x/logging#contextual-information
It's similar in that you use middleware to generate the request ID, but using Log::withContext you can directly add the request ID to all subsequent logs. So no need to register a service provider and call it manually every time you log something.
Please or to participate in this conversation.