From 542bd017c3078602d1dedda8ce3d2d3b3261d07d Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Tue, 12 Nov 2024 13:11:38 +0100 Subject: [PATCH] feat: add enable, disable logs --- examples/goma.yml | 4 ++-- internal/config.go | 2 ++ pkg/logger/logger.go | 15 +++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/goma.yml b/examples/goma.yml index 3bc23c2..c4e0ba5 100644 --- a/examples/goma.yml +++ b/examples/goma.yml @@ -90,8 +90,8 @@ gateway: # Route healthcheck healthCheck: path: /health/live - interval: 30 - timeout: 10 + interval: 30s + timeout: 10s healthyStatuses: - 200 - 404 diff --git a/internal/config.go b/internal/config.go index 8ff9ca8..faf15e5 100644 --- a/internal/config.go +++ b/internal/config.go @@ -157,6 +157,8 @@ func initConfig(configFile string) error { Rewrite: "/", HealthCheck: RouteHealthCheck{ Path: "/", + Interval: "30s", + Timeout: "10s", HealthyStatuses: []int{200, 404}, }, Middlewares: []string{"api-forbidden-paths"}, diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 278b4bc..b9e18b8 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -21,6 +21,7 @@ import ( "log" "os" "runtime" + "strings" "github.com/jkaninda/goma-gateway/util" ) @@ -59,7 +60,7 @@ func Fatal(msg string, args ...interface{}) { func Debug(msg string, args ...interface{}) { log.SetOutput(getStd(util.GetStringEnv("GOMA_ACCESS_LOG", "/dev/stdout"))) logLevel := util.GetStringEnv("GOMA_LOG_LEVEL", "") - if logLevel == "trace" || logLevel == "debug" { + if strings.ToLower(logLevel) == "trace" || strings.ToLower(logLevel) == "debug" { logWithCaller("DEBUG", msg, args...) } @@ -67,7 +68,7 @@ func Debug(msg string, args ...interface{}) { func Trace(msg string, args ...interface{}) { log.SetOutput(getStd(util.GetStringEnv("GOMA_ACCESS_LOG", "/dev/stdout"))) logLevel := util.GetStringEnv("GOMA_LOG_LEVEL", "") - if logLevel == "trace" { + if strings.ToLower(logLevel) == "trace" { logWithCaller("DEBUG", msg, args...) } @@ -89,10 +90,12 @@ func logWithCaller(level, msg string, args ...interface{}) { } // Log message with caller information if GOMA_LOG_LEVEL is trace logLevel := util.GetStringEnv("GOMA_LOG_LEVEL", "") - if logLevel == "trace" { - log.Printf("%s: %s (File: %s, Line: %d)\n", level, formattedMessage, file, line) - } else { - log.Printf("%s: %s\n", level, formattedMessage) + if strings.ToLower(logLevel) != "off" { + if strings.ToLower(logLevel) == "trace" { + log.Printf("%s: %s (File: %s, Line: %d)\n", level, formattedMessage, file, line) + } else { + log.Printf("%s: %s\n", level, formattedMessage) + } } }