gin-contrib / logger

Gin middleware/handler to logger url path using rs/zerolog
MIT License
192 stars 35 forks source link

chore(logger): update logger from context after middleware execution #52

Closed landerss1 closed 1 year ago

landerss1 commented 1 year ago

After middleware execution, the logger should be updated to reflect any changes to the context having been made in the middlewares. For example, if I have a tracing middleware that executes the following code, these attributes do not end up in the log:

l := zerolog.Ctx(c.Request.Context())
l.UpdateContext(func(c zerolog.Context) zerolog.Context {
    return c.Str("trace_id", span.SpanContext().TraceID().String()).
        Str("span_id", span.SpanContext().SpanID().String())
})

To make it work, we need to update the context after middlewares have executed.

appleboy commented 1 year ago

@landerss1 Please help to write some unit testing.

appleboy commented 1 year ago

@landerss1 Please create another PR. I have reverted this PR.