diff options
Diffstat (limited to 'srv/src/api/middleware.go')
-rw-r--r-- | srv/src/api/middleware.go | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/srv/src/api/middleware.go b/srv/src/api/middleware.go index 0b3eec7..fcd29b3 100644 --- a/srv/src/api/middleware.go +++ b/srv/src/api/middleware.go @@ -19,7 +19,7 @@ func addResponseHeaders(headers map[string]string, h http.Handler) http.Handler }) } -func annotateMiddleware(h http.Handler) http.Handler { +func setLoggerMiddleware(logger *mlog.Logger, h http.Handler) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { type reqInfoKey string @@ -34,6 +34,7 @@ func annotateMiddleware(h http.Handler) http.Handler { ) r = r.WithContext(ctx) + r = apiutil.SetRequestLogger(r, logger) h.ServeHTTP(rw, r) }) } @@ -58,11 +59,9 @@ func (lrw *logResponseWriter) WriteHeader(statusCode int) { lrw.ResponseWriter.WriteHeader(statusCode) } -func logMiddleware(logger *mlog.Logger, h http.Handler) http.Handler { +func logReqMiddleware(h http.Handler) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - r = apiutil.SetRequestLogger(r, logger) - lrw := newLogResponseWriter(rw) started := time.Now() @@ -77,7 +76,7 @@ func logMiddleware(logger *mlog.Logger, h http.Handler) http.Handler { logCtxKey("response_code"), lrw.statusCode, ) - logger.Info(ctx, "handled HTTP request") + apiutil.GetRequestLogger(r).Info(ctx, "handled HTTP request") }) } |