Skip to content

Commit

Permalink
Fix bug where dir is created instead of file
Browse files Browse the repository at this point in the history
  • Loading branch information
chiefMarlin committed Sep 13, 2023
1 parent 353f05a commit e162a3c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"os/signal"
"path/filepath"
"runtime"
"strings"
"syscall"
Expand All @@ -27,9 +28,13 @@ func tlog(logType string, logData string) {
}

if logFile != "" {
// Check if log file exists, if not create it along with the path
if _, err := os.Stat(logFile); os.IsNotExist(err) {
err := os.MkdirAll(logFile, 0755)
// Extract directory from the full path
dir := filepath.Dir(logFile)

// Check if directory exists
if _, err := os.Stat(dir); os.IsNotExist(err) {
// Create directory
err := os.MkdirAll(dir, 0755)
if err != nil {
fmt.Fprintf(os.Stderr, "error: cannot create log file path: %s\n", err)
os.Exit(4)
Expand Down

0 comments on commit e162a3c

Please sign in to comment.