RequestHandler adds the request method and URL as a field to the context's logger using fieldKey as field key.
(fieldKey string)
| 64 | // RequestHandler adds the request method and URL as a field to the context's logger |
| 65 | // using fieldKey as field key. |
| 66 | func RequestHandler(fieldKey string) func(next http.Handler) http.Handler { |
| 67 | return func(next http.Handler) http.Handler { |
| 68 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 69 | log := zerolog.Ctx(r.Context()) |
| 70 | log.UpdateContext(func(c zerolog.Context) zerolog.Context { |
| 71 | return c.Str(fieldKey, r.Method+" "+r.URL.String()) |
| 72 | }) |
| 73 | next.ServeHTTP(w, r) |
| 74 | }) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // RemoteAddrHandler adds the request's remote address as a field to the context's logger |
| 79 | // using fieldKey as field key. |