From 6bd46b438e7182624e1ad6ebd75aa14b87ee8e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Fri, 17 Sep 2021 20:35:41 +0200 Subject: [PATCH] exclude healthcheck from logs. --- internal/http/logger.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/http/logger.go b/internal/http/logger.go index 0f093ef0..2e946af1 100644 --- a/internal/http/logger.go +++ b/internal/http/logger.go @@ -17,6 +17,11 @@ type logFormatter struct { } func (l *logFormatter) NewLogEntry(r *http.Request) middleware.LogEntry { + // exclude healthcheck from logs + if r.RequestURI == "/api/health" { + return &nulllog{} + } + req := map[string]interface{}{} if reqID := middleware.GetReqID(r.Context()); reqID != "" { @@ -120,3 +125,11 @@ func (e *logEntry) Write(status, bytes int, header http.Header, elapsed time.Dur logger.Debug().Msgf("request complete (%d)", status) } + +type nulllog struct{} + +func (e *nulllog) Panic(v interface{}, stack []byte) {} +func (e *nulllog) Error(err error) {} +func (e *nulllog) SetSession(session types.Session) {} +func (e *nulllog) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) { +}