Skip to content

Commit 0436c79

Browse files
authored
warn level for status codes >500 (#187)
Statuses like 502 Bad Gateway or 503 Service Unavailable should not automatically result in an error log, if wanted this should be logged by the client code directly
1 parent 573482a commit 0436c79

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

helper.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,20 @@ func access(level logrus.Level, r *http.Request, start time.Time, statusCode int
110110
}
111111

112112
func accessLogLevelFor(level logrus.Level, r *http.Request, statusCode int) logrus.Level {
113+
if statusCode < 200 {
114+
// 100er codes are unexpected in the context of http handlers using this middleware
115+
return logrus.ErrorLevel
116+
}
113117
if statusCode >= 200 && statusCode <= 399 {
114118
if isHealthRequest(r) {
115119
return logrus.DebugLevel
116120
}
117121
return level
118-
} else if statusCode >= 400 && statusCode <= 499 {
119-
return logrus.WarnLevel
120122
}
121-
return logrus.ErrorLevel
123+
if statusCode == http.StatusInternalServerError {
124+
return logrus.ErrorLevel
125+
}
126+
return logrus.WarnLevel
122127
}
123128

124129
func isHealthRequest(r *http.Request) bool {

0 commit comments

Comments
 (0)