Skip to content

Commit

Permalink
logger: create parent directories if necessary
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne Wodey <etienne.wodey@aqt.eu>
  • Loading branch information
airwoodix authored and F1bonacc1 committed Jul 20, 2023
1 parent c191885 commit 328fecd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/pclog/logger_facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"github.com/rs/zerolog/log"
"os"
"path"
"sync"
"sync/atomic"

Expand Down Expand Up @@ -44,6 +45,11 @@ func (l *PCLog) Open(filePath string) {
log.Error().Msg("empty file path")
return
}
dirName := path.Dir(filePath)
if err := os.MkdirAll(dirName, 0700); err != nil && !os.IsExist(err) {
l.isClosed.Store(true)
log.Err(err).Msgf("failed to create log file directory %s", dirName)
}
f, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
l.isClosed.Store(true)
Expand Down

0 comments on commit 328fecd

Please sign in to comment.