From 420c6a875419c339457efee71ec70948d1ecbd5e Mon Sep 17 00:00:00 2001 From: linzeliang Date: Tue, 30 Apr 2024 18:09:33 +0800 Subject: [PATCH] feat: support one or more log file --- common/config/config.go | 2 ++ common/logger/logger.go | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/common/config/config.go b/common/config/config.go index 0864d8442e..aaa2673128 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -144,3 +144,5 @@ var MetricFailChanSize = env.Int("METRIC_FAIL_CHAN_SIZE", 128) var InitialRootToken = os.Getenv("INITIAL_ROOT_TOKEN") var GeminiVersion = env.String("GEMINI_VERSION", "v1") + +var OnlyOneLogFile = env.Bool("ONLY_ONE_LOG_FILE", false) \ No newline at end of file diff --git a/common/logger/logger.go b/common/logger/logger.go index c3dcd89d03..1df7a5bb93 100644 --- a/common/logger/logger.go +++ b/common/logger/logger.go @@ -27,7 +27,12 @@ var setupLogOnce sync.Once func SetupLogger() { setupLogOnce.Do(func() { if LogDir != "" { - logPath := filepath.Join(LogDir, fmt.Sprintf("oneapi-%s.log", time.Now().Format("20060102"))) + var logPath string + if config.OnlyOneLogFile { + logPath = filepath.Join(LogDir, "oneapi.log") + } else { + logPath = filepath.Join(LogDir, fmt.Sprintf("oneapi-%s.log", time.Now().Format("20060102"))) + } fd, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { log.Fatal("failed to open log file")