Browse Source

http: Only log handler errors >= 500

Errors in the 4xx range are client errors, and they don't need to be
entered into the server's error logs. 4xx errors are still recorded in
the access logs at the error level.
master
Matthew Holt 6 years ago
parent
commit
d55fa68902
No known key found for this signature in database GPG Key ID: 2A349DD577D586A5
  1. 8
      modules/caddyhttp/server.go

8
modules/caddyhttp/server.go

@ -152,7 +152,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err2 == nil {
// user's error route handled the error response
// successfully, so now just log the error
logger.Error(errMsg, errFields...)
if errStatus >= 500 {
logger.Error(errMsg, errFields...)
}
} else {
// well... this is awkward
errFields = append([]zapcore.Field{
@ -163,7 +165,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
logger.Error("error handling handler error", errFields...)
}
} else {
logger.Error(errMsg, errFields...)
if errStatus >= 500 {
logger.Error(errMsg, errFields...)
}
w.WriteHeader(errStatus)
}
}

Loading…
Cancel
Save