Skip to content

Commit

Permalink
feat: support one or more log file (songquanpeng#1400)
Browse files Browse the repository at this point in the history
Co-authored-by: Laisky.Cai <github@laisky.com>
  • Loading branch information
2 people authored and mxdlzg committed Oct 15, 2024
1 parent ebe4561 commit 82aa363
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ var InitialRootToken = os.Getenv("INITIAL_ROOT_TOKEN")

var GeminiVersion = env.String("GEMINI_VERSION", "v1")


var OnlyOneLogFile = env.Bool("ONLY_ONE_LOG_FILE", false)

var RelayProxy = env.String("RELAY_PROXY", "")
var UserContentRequestProxy = env.String("USER_CONTENT_REQUEST_PROXY", "")
var UserContentRequestTimeout = env.Int("USER_CONTENT_REQUEST_TIMEOUT", 30)
7 changes: 6 additions & 1 deletion common/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 82aa363

Please sign in to comment.