日志文件bug修复

This commit is contained in:
Pan Qiancheng 2025-04-25 16:42:06 +08:00
parent 410afb67fb
commit e2fd36195d
1 changed files with 13 additions and 1 deletions

View File

@ -320,7 +320,19 @@ func startDaemonProcess() error {
} }
goTimeFormat := formatGoTime(constants.LogNameFormate) goTimeFormat := formatGoTime(constants.LogNameFormate)
logFileName := time.Now().Format(goTimeFormat) logFileName := time.Now().Format(goTimeFormat)
logFilePath := filepath.Join(constants.LogFilePath, logFileName) // logFilePath := filepath.Join(constants.LogFilePath, logFileName)
var logFilePath string
if isDebug() {
logFilePath = filepath.Join(constants.LogFilePath, logFileName)
} else {
exePath, err := os.Executable()
if err != nil {
logger.Error("Error getting executable path: %v", err)
return err
}
exeDir := filepath.Dir(exePath)
logFilePath = filepath.Join(exeDir, constants.LogFilePath, logFileName)
}
logFile, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, constants.LogFileMode) logFile, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, constants.LogFileMode)
if err != nil { if err != nil {
return fmt.Errorf("open log file: %w", err) return fmt.Errorf("open log file: %w", err)