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

This commit is contained in:
殷勇 2023-08-28 13:12:45 +08:00
parent 0463bb48fc
commit 28e2d3ea05

View File

@ -1,11 +1,12 @@
package f5
import (
"fmt"
"os"
"q5"
"runtime"
"sync"
"time"
"fmt"
"q5"
)
const (
@ -18,8 +19,11 @@ const (
LOG_EMERGENCY = iota
)
const SYS_LOG_ROOT = "/data/logs/%s/logs/"
const SYS_LOG_FILENAME = "log_%d_%s.log"
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"
)
type LogMsgNode struct {
category int32
@ -128,7 +132,7 @@ func (this *SysLog_) goSaveToFile() {
this.botNode = nil
this.msgMutex.Unlock()
if workNode != nil {
logDir := fmt.Sprintf(SYS_LOG_ROOT, GetApp().GetPkgName())
logDir := this.GetLogDir()
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 {
@ -143,3 +147,12 @@ 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
}