From 6d27072719b8ebfaf8b21ab5c5ab497fb08f97ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilson=20J=C3=BAnior?= Date: Mon, 9 Dec 2024 18:45:48 -0300 Subject: [PATCH] Enhance logging middleware to skip healthcheck and metrics paths with custom log format --- pkg/web/api.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/web/api.go b/pkg/web/api.go index e516317f..88e73ba5 100644 --- a/pkg/web/api.go +++ b/pkg/web/api.go @@ -168,7 +168,19 @@ func newEcho(targetFactory target.Factory) *echo.Echo { observability.Initialize() e.Use(middleware.Recover()) - e.Use(middleware.Logger()) + e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Skipper: func(c echo.Context) bool { + if c.Path() == "/healthcheck" || c.Path() == "/metrics" { + return true + } + return false + }, + Format: `{"time":"${time_rfc3339_nano}","id":"${id}","remote_ip":"${remote_ip}",` + + `"host":"${host}","method":"${method}","uri":"${uri}","user_agent":"${user_agent}",` + + `"status":${status},"error":"${error}","latency":${latency},"latency_human":"${latency_human}"` + + `,"bytes_in":${bytes_in},"bytes_out":${bytes_out}}` + "\n", + CustomTimeFormat: "2006-01-02 15:04:05.00000", + })) e.Use(metricsMiddleware) e.Use(observability.OpenTracingMiddleware) e.Use(middleware.BasicAuthWithConfig(middleware.BasicAuthConfig{