syslog日志路径 添加windows目录支持

This commit is contained in:
殷勇 2023-08-28 13:58:31 +08:00
parent 28e2d3ea05
commit 3584ff5e7e
3 changed files with 18 additions and 14 deletions

8
constant_unix.go Normal file
View File

@ -0,0 +1,8 @@
//go:build unix
// +build unix
package f5
const (
SYS_LOG_ROOT = "/data/logs/%s/logs/"
)

8
constant_windows.go Normal file
View File

@ -0,0 +1,8 @@
//go:build windows
// +build windows
package f5
const (
SYS_LOG_ROOT = "d:/linux_root/data/logs/%s/logs/"
)

View File

@ -4,7 +4,6 @@ import (
"fmt"
"os"
"q5"
"runtime"
"sync"
"time"
)
@ -20,9 +19,7 @@ const (
)
const (
SYS_LOG_ROOT_LINUX = "/data/logs/%s/logs/"
SYS_LOG_ROOT_WINDOWS = "d:/linux_root/data/logs/%s/logs/"
SYS_LOG_FILENAME = "log_%d_%s.log"
SYS_LOG_FILENAME = "log_%d_%s.log"
)
type LogMsgNode struct {
@ -132,7 +129,7 @@ func (this *SysLog_) goSaveToFile() {
this.botNode = nil
this.msgMutex.Unlock()
if workNode != nil {
logDir := this.GetLogDir()
logDir := fmt.Sprintf(SYS_LOG_ROOT, GetApp().GetPkgName())
fileName := fmt.Sprintf(TGLOG_FILENAME, os.Getpid(), time.Now().Format("20060102"))
q5.ForceCreateDir(logDir)
if f, err := os.OpenFile(logDir+fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666); err == nil {
@ -147,12 +144,3 @@ func (this *SysLog_) goSaveToFile() {
}
}
}
func (this *SysLog_) GetLogDir() string {
pkgName := GetApp().GetPkgName()
var logDir string = fmt.Sprintf(SYS_LOG_ROOT_LINUX, pkgName)
if runtime.GOOS == "windows" {
logDir = fmt.Sprintf(SYS_LOG_ROOT_WINDOWS, pkgName)
}
return logDir
}