I am writing a web application using golang. I am new to this language. I am trying to find what is the best way followed to log requestid in golang webapp. I have decided to use either go's log library (https://golang.org/pkg/log/) or logrus (https://github.com/sirupsen/logrus). It looks to me both of these does not provide anything related to requestId logging. So for generating requestId and using it through out the api's flow I have arrived to following approach for now
Use any one of the uid generation library listed here(https://golanglibs.com/search?q=id+generator&sort=top) to generate requestid. And set it in the context(https://golang.org/pkg/context/) at the start of processing the request by using http.Handler wrapper . And use this context in all the places wherever I want to log.
But to achieve this I need to pass the context object to all the functions where I need to log something. It does not sound good to me since I am touching all the function's prototype(i.e.adding context param). Is there any better way to do this? Something like ThreadLocal object. And it can be accessed from anywhere within the thread and using which we can get the request id wherever we need?