From cc03c1e91041859f69ea403b921b15fb90f27272 Mon Sep 17 00:00:00 2001 From: Thomas <27960254+thomiceli@users.noreply.github.com> Date: Sun, 28 Jun 2026 02:48:00 +0700 Subject: [PATCH] Add log path config (#745) --- config.yml | 3 +++ docs/configuration/cheat-sheet.md | 1 + internal/config/config.go | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config.yml b/config.yml index a1dc63c..f9df36f 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 directory where the log file (opengist.log) is written. Default: $OG_OPENGIST_HOME/log +log-path: + # Public URL to access to Opengist external-url: diff --git a/docs/configuration/cheat-sheet.md b/docs/configuration/cheat-sheet.md index d4b7534..6fcceb4 100644 --- a/docs/configuration/cheat-sheet.md +++ b/docs/configuration/cheat-sheet.md @@ -8,6 +8,7 @@ aside: false |--------------------------|-------------------------------------|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | log-level | OG_LOG_LEVEL | `warn` | Set the log level to one of the following: `debug`, `info`, `warn`, `error`, `fatal`. | | log-output | OG_LOG_OUTPUT | `stdout,file` | Set the log output to one or more of the following: `stdout`, `file`. | +| log-path | OG_LOG_PATH | `$opengist-home/log` | Set the directory where the log file (`opengist.log`) is written. | | external-url | OG_EXTERNAL_URL | none | Public URL to access to Opengist. | | opengist-home | OG_OPENGIST_HOME | home directory | Path to the directory where Opengist stores its data. | | secret-key | OG_SECRET_KEY | randomized 32 bytes | Secret key used for session store & encrypt MFA data on database. | diff --git a/internal/config/config.go b/internal/config/config.go index 7f20b8f..e81589c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -41,6 +41,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"` @@ -205,6 +206,10 @@ func InitConfig(configPath string, out io.Writer) error { C = c + if c.LogPath == "" { + c.LogPath = filepath.Join(GetHomeDir(), "log") + } + if err = migrateConfig(); err != nil { return err } @@ -216,7 +221,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) } @@ -257,7 +262,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) }