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"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|
@ -74,6 +75,12 @@ func InitWithLogLevel(logLevel LogLevel, logPath string) error {
|
||||||
Level: level,
|
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
|
// add another writer to write to a log file
|
||||||
if logPath != "" {
|
if logPath != "" {
|
||||||
LogFile, err = os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
|
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