fix: added logic to make directory for log file

This commit is contained in:
David Allen 2025-09-03 17:38:41 -06:00
parent 3ced4e4fd4
commit cd0058dfa4
Signed by: towk
GPG key ID: 0430CDBE22619155

View file

@ -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)