Skip to content

Commit

Permalink
Ensure log file directory exists before creating the log file
Browse files Browse the repository at this point in the history
  • Loading branch information
yunkon-kim committed Sep 25, 2024
1 parent 0b76346 commit ee3fccc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/core/common/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ func NewLogger(config Config) *zerolog.Logger {
Compress: config.Compress,
}

// Ensure the log file directory exists before creating the log file
dir := filepath.Dir(config.LogFilePath)
if _, err := os.Stat(dir); os.IsNotExist(err) {
// Create the directory if it does not exist
err = os.MkdirAll(dir, 0755) // Set permissions as needed
if err != nil {
log.Fatal().Msgf("Failed to create log directory: %v", err)
}
}

// Ensure the log file exists before changing its permissions
if _, err := os.Stat(config.LogFilePath); os.IsNotExist(err) {
// Create the log file if it does not exist
Expand Down

0 comments on commit ee3fccc

Please sign in to comment.