Logging request id in go

we have a web server written in GO. we are using the gorilla/mux package.
we want to add a request id to all the logs on the handler side - so that we will be able distinguish later which log is related to which request (we can receive a lot of requests that can be processed in the same time)

Is there an easy way yo do this? that does not include passing some context or request id down the call chain to all the functions , and adding them by hand to the log?

(I understand that using the goroutine id is not good\recommended, so we are looking for some other easy solution if one exists.)

thanks!

Check this implementation, the usual way is to generate an ID and inject it into the request context so that you can access it from any middleware. Some projects use UUID.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.