diff --git a/httptransport/logginghandler.go b/httptransport/logginghandler.go index 83c0f14a30..13b8fdb92a 100644 --- a/httptransport/logginghandler.go +++ b/httptransport/logginghandler.go @@ -10,7 +10,6 @@ import ( type httpStatusWriter struct { http.ResponseWriter - StatusCode int } @@ -21,13 +20,16 @@ func LoggingHandler(next http.Handler) http.HandlerFunc { log := zerolog.Ctx(r.Context()) + // default HTTP StatusOK + lrw := &httpStatusWriter{ResponseWriter: w, StatusCode: http.StatusOK} + next.ServeHTTP(w, r) log.Info(). Str("remote addr", r.RemoteAddr). Str("method", r.Method). Str("request uri", r.RequestURI). - Str("status", strconv.Itoa(http.StatusOK)). + Str("status", strconv.Itoa(lrw.StatusCode)). Float64("elapsed time (md)", float64(time.Since(start).Nanoseconds())*1e-6). Msg("handled HTTP request") }