Skip to content

Commit

Permalink
[fix] Better report HTTP statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
0x416e746f6e committed Oct 30, 2023
1 parent 48c1103 commit 5e5f56e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions httplogger/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func Middleware(logger *zap.Logger, next http.Handler) http.Handler {

// Passing request stats both in-message (for the human reader)
// as well as inside the structured log (for the machine parser)
logger.Info(fmt.Sprintf("%s: %s %s %d", r.URL.Scheme, r.Method, r.URL.EscapedPath(), wrapped.status),
logger.Info(fmt.Sprintf("%s: %s %s %d", r.URL.Scheme, r.Method, r.URL.EscapedPath(), wrapped.Status()),
zap.Int("durationMs", int(time.Since(start).Milliseconds())),
zap.Int("status", wrapped.status),
zap.Int("status", wrapped.Status()),
zap.String("httpRequestID", httpRequestID),
zap.String("logType", "access"),
zap.String("method", r.Method),
Expand Down
5 changes: 4 additions & 1 deletion httplogger/response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ func wrapResponseWriter(w http.ResponseWriter) *responseWriter {
}

func (rw *responseWriter) Status() int {
return rw.status
if rw.wroteHeader {
return rw.status
}
return http.StatusOK
}

func (rw *responseWriter) WriteHeader(code int) {
Expand Down

0 comments on commit 5e5f56e

Please sign in to comment.