Change response logging message

to allow specific error tracking in sentry. See POSEIDON-F
This commit is contained in:
Maximilian Paß
2021-11-26 21:14:27 +01:00
parent a6eaa45097
commit 7c9406cd7a
2 changed files with 3 additions and 3 deletions

View File

@ -66,7 +66,7 @@ func (writer *loggingResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, erro
return conn, rw, nil
}
// HTTPLoggingMiddleware returns an http.Handler that logs different information about every request.
// HTTPLoggingMiddleware returns a http.Handler that logs different information about every request.
func HTTPLoggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now().UTC()
@ -84,7 +84,7 @@ func HTTPLoggingMiddleware(next http.Handler) http.Handler {
"user_agent": r.UserAgent(),
})
if lrw.statusCode >= http.StatusInternalServerError {
logEntry.Warn()
logEntry.Error("Failing " + path)
} else {
logEntry.Debug()
}

View File

@ -28,7 +28,7 @@ func TestHTTPMiddlewareWarnsWhenInternalServerError(t *testing.T) {
HTTPLoggingMiddleware(mockHTTPStatusHandler(500)).ServeHTTP(recorder, request)
assert.Equal(t, 1, len(hook.Entries))
assert.Equal(t, logrus.WarnLevel, hook.LastEntry().Level)
assert.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level)
}
func TestHTTPMiddlewareDebugsWhenStatusOK(t *testing.T) {