From 63ee0f23c74a6b0dbb571ea1697d789426ed06a9 Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Thu, 9 Jun 2022 12:25:06 +0100 Subject: [PATCH] tweaking logger to only output in debug mode --- cmd/internal/setup.go | 8 ++++++-- cmd/server/main.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/internal/setup.go b/cmd/internal/setup.go index 1ee4799..70bc5b8 100644 --- a/cmd/internal/setup.go +++ b/cmd/internal/setup.go @@ -70,13 +70,17 @@ func SetupDeps(cfg config.Config, l log.Logger) *Deps { } // SetupEcho will set up and return an echo server. -func SetupEcho(l log.Logger) *echo.Echo { +func SetupEcho(cfg *config.Config, l log.Logger) *echo.Echo { e := echo.New() e.HideBanner = true // Middleware e.Use(middleware.Recover()) - e.Use(middleware.Logger()) + e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Skipper: func(c echo.Context) bool { + return cfg.Logging.Level != config.LogDebug + }, + })) e.Use(middleware.RequestID()) e.Use(middleware.CORSWithConfig(middleware.CORSConfig{ AllowOrigins: []string{"*"}, diff --git a/cmd/server/main.go b/cmd/server/main.go index 47370bf..276cf79 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -57,7 +57,7 @@ func main() { log.Fatal(err, "config error") } - e := internal.SetupEcho(log) + e := internal.SetupEcho(cfg,log) if cfg.Server.SwaggerEnabled { internal.SetupSwagger(*cfg.Server, e)