feat: add enable, disable logs

This commit is contained in:
Jonas Kaninda
2024-11-12 13:11:38 +01:00
parent a99c40940e
commit 542bd017c3
3 changed files with 13 additions and 8 deletions

View File

@@ -90,8 +90,8 @@ gateway:
# Route healthcheck
healthCheck:
path: /health/live
interval: 30
timeout: 10
interval: 30s
timeout: 10s
healthyStatuses:
- 200
- 404

View File

@@ -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"},

View File

@@ -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,11 +90,13 @@ 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" {
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)
}
}
}
func getStd(out string) *os.File {