fix: added logic to make directory for log file
This commit is contained in:
parent
3ced4e4fd4
commit
cd0058dfa4
1 changed files with 7 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue