From 59440faedbc8898c2be6e5d9f5d3efb821983c02 Mon Sep 17 00:00:00 2001 From: Thomas Miceli Date: Thu, 5 Jun 2025 11:18:03 +0200 Subject: [PATCH] Specify log path --- config.yml | 3 +++ internal/config/config.go | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/config.yml b/config.yml index cde43f6..ed3d2d5 100644 --- a/config.yml +++ b/config.yml @@ -8,6 +8,9 @@ log-level: warn # Set the log output to one or more of the following: `stdout`, `file`. Default: stdout,file log-output: stdout,file +# Set the path to the log file. +log-path: /tmp/logaaa + # Public URL to access to Opengist external-url: diff --git a/internal/config/config.go b/internal/config/config.go index 1925fdb..9de28b3 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -31,6 +31,7 @@ type config struct { LogLevel string `yaml:"log-level" env:"OG_LOG_LEVEL"` LogOutput string `yaml:"log-output" env:"OG_LOG_OUTPUT"` + LogPath string `yaml:"log-path" env:"OG_LOG_PATH"` ExternalUrl string `yaml:"external-url" env:"OG_EXTERNAL_URL"` OpengistHome string `yaml:"opengist-home" env:"OG_OPENGIST_HOME"` @@ -152,6 +153,10 @@ func InitConfig(configPath string, out io.Writer) error { c.OpengistHome = filepath.Join(homeDir, ".opengist") } + if c.LogPath == "" { + c.LogPath = filepath.Join(GetHomeDir(), "log") + } + if err = checks(c); err != nil { return err } @@ -169,7 +174,7 @@ func InitConfig(configPath string, out io.Writer) error { } func InitLog() { - if err := os.MkdirAll(filepath.Join(GetHomeDir(), "log"), 0755); err != nil { + if err := os.MkdirAll(C.LogPath, 0755); err != nil { panic(err) } @@ -210,7 +215,7 @@ func InitLog() { logWriters = append(logWriters, consoleWriter) defer func() { log.Debug().Msg("Logging to stdout") }() case "file": - file, err := os.OpenFile(filepath.Join(GetHomeDir(), "log", "opengist.log"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + file, err := os.OpenFile(filepath.Join(C.LogPath, "opengist.log"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { panic(err) }