Skip to content

Commit

Permalink
fix(dir): read working dir or fullpath directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ibnumardini committed May 8, 2023
1 parent 7d0eb40 commit 12b4f29
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions logn.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,15 @@ func makeLog(logTypes int, title string, logMessage interface{}, loc string) err
return err
}

workingDir, err := os.Getwd()
if err != nil {
return err
}

var dates = map[string]string{
"year": config.Log.LognDir + year,
"month": config.Log.LognDir + year + "/" + month,
"day": config.Log.LognDir + year + "/" + month + "/" + day,
"year": fmt.Sprintf("%s/%s%s", workingDir, config.Log.LognDir, year),
"month": fmt.Sprintf("%s/%s%s/%s", workingDir, config.Log.LognDir, year, month),
"day": fmt.Sprintf("%s/%s%s/%s/%s", workingDir, config.Log.LognDir, year, month, day),
}

for _, date := range dates {
Expand All @@ -122,7 +127,7 @@ func makeLog(logTypes int, title string, logMessage interface{}, loc string) err
}
}

logFile := config.Log.LognDir + year + "/" + month + "/" + day + "/" + logType + ".log"
logFile := fmt.Sprintf("%s/%s%s/%s/%s/%s.log", workingDir, config.Log.LognDir, year, month, day, logType)

file, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
Expand Down

0 comments on commit 12b4f29

Please sign in to comment.