Skip to content

Commit

Permalink
Enhance logging middleware to skip healthcheck and metrics paths with…
Browse files Browse the repository at this point in the history
… custom log format
  • Loading branch information
wpjunior committed Dec 9, 2024
1 parent 2097a03 commit 6d27072
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/web/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 6d27072

Please sign in to comment.