diff --git a/pkg/log/log.go b/pkg/log/log.go index 90ffa8d..95735b6 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "os" + "path/filepath" "slices" "strings" @@ -74,6 +75,12 @@ func InitWithLogLevel(logLevel LogLevel, logPath string) error { Level: level, }) + // make the log directory if necessary + err = os.MkdirAll(filepath.Dir(logPath), 0o777) + if err != nil { + return fmt.Errorf("failed to create log path directory: %v", err) + } + // add another writer to write to a log file if logPath != "" { LogFile, err = os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)