Skip to content

Commit

Permalink
Default to 200OK, otherwise get the HTTP return status
Browse files Browse the repository at this point in the history
  • Loading branch information
mcoops committed Sep 15, 2020
1 parent 3c87d98 commit 1f0619f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions httptransport/logginghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

type httpStatusWriter struct {
http.ResponseWriter

StatusCode int
}

Expand All @@ -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")
}
Expand Down

0 comments on commit 1f0619f

Please sign in to comment.