Merged pull request #523 from influxdata/nc-http-error-logging

feat: add errors to http logging
pull/10616/head
Nathaniel Cook 2018-07-31 14:44:08 -06:00
commit 217d1d8f66
1 changed files with 5 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package http
import (
"context"
"encoding/json"
"errors"
"net/http"
_ "net/http/pprof"
"strings"
@ -94,12 +95,16 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
"status": statusClass,
}).Observe(duration.Seconds())
if h.Logger != nil {
err := errors.New(w.Header().Get(ErrorHeader))
errReference := w.Header().Get(ReferenceHeader)
h.Logger.Info("served http request",
zap.String("handler", h.name),
zap.String("method", r.Method),
zap.String("path", r.URL.Path),
zap.Int("status", statusCode),
zap.Int("duration_ns", int(duration)),
zap.Error(err),
zap.String("reference", errReference),
)
}
}(time.Now())