diff --git a/httptransport/logginghandler.go b/httptransport/logginghandler.go index 13b8fdb92a..3fb85e4a0a 100644 --- a/httptransport/logginghandler.go +++ b/httptransport/logginghandler.go @@ -2,7 +2,6 @@ package httptransport import ( "net/http" - "strconv" "time" "github.com/rs/zerolog" @@ -13,6 +12,11 @@ type httpStatusWriter struct { StatusCode int } +func (lrw *httpStatusWriter) WriteHeader(code int) { + lrw.StatusCode = code + lrw.ResponseWriter.WriteHeader(code) +} + // LoggingHandler will log HTTP requests using the pre initialized zerolog. func LoggingHandler(next http.Handler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -23,13 +27,13 @@ func LoggingHandler(next http.Handler) http.HandlerFunc { // default HTTP StatusOK lrw := &httpStatusWriter{ResponseWriter: w, StatusCode: http.StatusOK} - next.ServeHTTP(w, r) + next.ServeHTTP(lrw, r) log.Info(). Str("remote addr", r.RemoteAddr). Str("method", r.Method). Str("request uri", r.RequestURI). - Str("status", strconv.Itoa(lrw.StatusCode)). + Int("status", lrw.StatusCode). Float64("elapsed time (md)", float64(time.Since(start).Nanoseconds())*1e-6). Msg("handled HTTP request") }