diff --git a/src/api/rest/server/middlewares/custom-middleware.go b/src/api/rest/server/middlewares/custom-middleware.go index e67e91c1b..3a87678fe 100644 --- a/src/api/rest/server/middlewares/custom-middleware.go +++ b/src/api/rest/server/middlewares/custom-middleware.go @@ -12,22 +12,16 @@ import ( "github.com/rs/zerolog/log" ) -func skipLogging(uri string) bool { - skipPatterns := []string{ - "/tumblebug/api", - "/mcis?option=status", - } - - for _, pattern := range skipPatterns { - if strings.Contains(uri, pattern) { - return true - } - } - return false -} - -func Zerologger() echo.MiddlewareFunc { +func Zerologger(skipPatterns []string) echo.MiddlewareFunc { return middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ + Skipper: func(c echo.Context) bool { + for _, pattern := range skipPatterns { + if strings.Contains(c.Request().URL.Path, pattern) { + return true + } + } + return false + }, LogError: true, LogRequestID: true, LogRemoteIP: true, @@ -41,9 +35,6 @@ func Zerologger() echo.MiddlewareFunc { LogResponseSize: true, // HandleError: true, // forwards error to the global error handler, so it can decide appropriate status code LogValuesFunc: func(c echo.Context, v middleware.RequestLoggerValues) error { - if skipLogging(v.URI) { - return nil - } if v.Error == nil { log.Info(). Str("id", v.RequestID). diff --git a/src/api/rest/server/server.go b/src/api/rest/server/server.go index 66d73dea5..4c374732c 100644 --- a/src/api/rest/server/server.go +++ b/src/api/rest/server/server.go @@ -89,7 +89,12 @@ func RunServer(port string) { // Middleware // e.Use(middleware.Logger()) - e.Use(middlewares.Zerologger()) + APILogSkipPatterns := []string{ + "/tumblebug/api", + "/mcis?option=status", + } + e.Use(middlewares.Zerologger(APILogSkipPatterns)) + e.Use(middleware.Recover()) // limit the application to 20 requests/sec using the default in-memory store e.Use(middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(20)))