Skip to content

Commit

Permalink
pkg/httplog: change log levels for 4xx and 501 status
Browse files Browse the repository at this point in the history
this changes 4xx to debug level, and 501 to warning level to
stop the log clutter when we run at info level in production.

Closes #387

Change-Id: I861cdbf8af5dbf51a35016bc42bcc23b0e079347
  • Loading branch information
halkyon committed Jan 31, 2024
1 parent 3d4d8c7 commit 74c842a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/httplog/httplog.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
// StatusLevel takes an HTTP status and returns an appropriate log level.
func StatusLevel(status int) zapcore.Level {
switch {
case status == 501:
return zap.WarnLevel
case status >= 500:
return zap.ErrorLevel
case status >= 400:
return zap.InfoLevel
default:
return zap.DebugLevel
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/httplog/httplog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func TestStatusLevel(t *testing.T) {
},
{
status: http.StatusBadRequest,
expectedLevel: zap.InfoLevel,
expectedLevel: zap.DebugLevel,
},
{
status: http.StatusNotFound,
expectedLevel: zap.InfoLevel,
expectedLevel: zap.DebugLevel,
},
{
status: http.StatusInternalServerError,
Expand All @@ -50,6 +50,10 @@ func TestStatusLevel(t *testing.T) {
status: http.StatusBadGateway,
expectedLevel: zap.ErrorLevel,
},
{
status: http.StatusNotImplemented,
expectedLevel: zap.WarnLevel,
},
}
for _, tc := range testCases {
tc := tc
Expand Down

0 comments on commit 74c842a

Please sign in to comment.