From 3584ff5e7ebdd4186fe26abed7c4ad79b845246d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B7=E5=8B=87?= Date: Mon, 28 Aug 2023 13:58:31 +0800 Subject: [PATCH] =?UTF-8?q?syslog=E6=97=A5=E5=BF=97=E8=B7=AF=E5=BE=84=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0windows=E7=9B=AE=E5=BD=95=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constant_unix.go | 8 ++++++++ constant_windows.go | 8 ++++++++ syslog.go | 16 ++-------------- 3 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 constant_unix.go create mode 100644 constant_windows.go diff --git a/constant_unix.go b/constant_unix.go new file mode 100644 index 0000000..7de33c5 --- /dev/null +++ b/constant_unix.go @@ -0,0 +1,8 @@ +//go:build unix +// +build unix + +package f5 + +const ( + SYS_LOG_ROOT = "/data/logs/%s/logs/" +) diff --git a/constant_windows.go b/constant_windows.go new file mode 100644 index 0000000..a7a538f --- /dev/null +++ b/constant_windows.go @@ -0,0 +1,8 @@ +//go:build windows +// +build windows + +package f5 + +const ( + SYS_LOG_ROOT = "d:/linux_root/data/logs/%s/logs/" +) diff --git a/syslog.go b/syslog.go index baa5f77..e166699 100644 --- a/syslog.go +++ b/syslog.go @@ -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 -}