feat: add enable, disable logs
This commit is contained in:
@@ -90,8 +90,8 @@ gateway:
|
||||
# Route healthcheck
|
||||
healthCheck:
|
||||
path: /health/live
|
||||
interval: 30
|
||||
timeout: 10
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
healthyStatuses:
|
||||
- 200
|
||||
- 404
|
||||
|
||||
@@ -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"},
|
||||
|
||||
@@ -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,12 +90,14 @@ 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 {
|
||||
switch out {
|
||||
|
||||
Reference in New Issue
Block a user