Skip to content
Snippets Groups Projects
Commit 3276bdc5 authored by gbe's avatar gbe
Browse files

Fix accumulating log attributes

`logger` is a closure here, so overwriting it on every request isn't a good idea.
parent ce75caaa
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@ func Request(next http.Handler, logger log.Logger) http.Handler {
remote = r.RemoteAddr
}
logger = log.With(logger,
l := log.With(logger,
"method", r.Method,
"url", r.URL,
"remote", remote,
......@@ -31,13 +31,13 @@ func Request(next http.Handler, logger log.Logger) http.Handler {
defer func() {
d := time.Since(start)
level.Info(logger).
level.Info(l).
Log("duration", d,
"msg", "request handled")
}()
key := contextKey("logger")
ctx := context.WithValue(r.Context(), key, logger)
ctx := context.WithValue(r.Context(), key, l)
next.ServeHTTP(w, r.WithContext(ctx))
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment