feat: add enable, disable logs
This commit is contained in:
@@ -90,8 +90,8 @@ gateway:
|
|||||||
# Route healthcheck
|
# Route healthcheck
|
||||||
healthCheck:
|
healthCheck:
|
||||||
path: /health/live
|
path: /health/live
|
||||||
interval: 30
|
interval: 30s
|
||||||
timeout: 10
|
timeout: 10s
|
||||||
healthyStatuses:
|
healthyStatuses:
|
||||||
- 200
|
- 200
|
||||||
- 404
|
- 404
|
||||||
|
|||||||
@@ -157,6 +157,8 @@ func initConfig(configFile string) error {
|
|||||||
Rewrite: "/",
|
Rewrite: "/",
|
||||||
HealthCheck: RouteHealthCheck{
|
HealthCheck: RouteHealthCheck{
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
Interval: "30s",
|
||||||
|
Timeout: "10s",
|
||||||
HealthyStatuses: []int{200, 404},
|
HealthyStatuses: []int{200, 404},
|
||||||
},
|
},
|
||||||
Middlewares: []string{"api-forbidden-paths"},
|
Middlewares: []string{"api-forbidden-paths"},
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/jkaninda/goma-gateway/util"
|
"github.com/jkaninda/goma-gateway/util"
|
||||||
)
|
)
|
||||||
@@ -59,7 +60,7 @@ func Fatal(msg string, args ...interface{}) {
|
|||||||
func Debug(msg string, args ...interface{}) {
|
func Debug(msg string, args ...interface{}) {
|
||||||
log.SetOutput(getStd(util.GetStringEnv("GOMA_ACCESS_LOG", "/dev/stdout")))
|
log.SetOutput(getStd(util.GetStringEnv("GOMA_ACCESS_LOG", "/dev/stdout")))
|
||||||
logLevel := util.GetStringEnv("GOMA_LOG_LEVEL", "")
|
logLevel := util.GetStringEnv("GOMA_LOG_LEVEL", "")
|
||||||
if logLevel == "trace" || logLevel == "debug" {
|
if strings.ToLower(logLevel) == "trace" || strings.ToLower(logLevel) == "debug" {
|
||||||
logWithCaller("DEBUG", msg, args...)
|
logWithCaller("DEBUG", msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +68,7 @@ func Debug(msg string, args ...interface{}) {
|
|||||||
func Trace(msg string, args ...interface{}) {
|
func Trace(msg string, args ...interface{}) {
|
||||||
log.SetOutput(getStd(util.GetStringEnv("GOMA_ACCESS_LOG", "/dev/stdout")))
|
log.SetOutput(getStd(util.GetStringEnv("GOMA_ACCESS_LOG", "/dev/stdout")))
|
||||||
logLevel := util.GetStringEnv("GOMA_LOG_LEVEL", "")
|
logLevel := util.GetStringEnv("GOMA_LOG_LEVEL", "")
|
||||||
if logLevel == "trace" {
|
if strings.ToLower(logLevel) == "trace" {
|
||||||
logWithCaller("DEBUG", msg, args...)
|
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
|
// Log message with caller information if GOMA_LOG_LEVEL is trace
|
||||||
logLevel := util.GetStringEnv("GOMA_LOG_LEVEL", "")
|
logLevel := util.GetStringEnv("GOMA_LOG_LEVEL", "")
|
||||||
if logLevel == "trace" {
|
if strings.ToLower(logLevel) != "off" {
|
||||||
log.Printf("%s: %s (File: %s, Line: %d)\n", level, formattedMessage, file, line)
|
if strings.ToLower(logLevel) == "trace" {
|
||||||
} else {
|
log.Printf("%s: %s (File: %s, Line: %d)\n", level, formattedMessage, file, line)
|
||||||
log.Printf("%s: %s\n", level, formattedMessage)
|
} else {
|
||||||
|
log.Printf("%s: %s\n", level, formattedMessage)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user