From bf757a2bccbcd2ba05639d15690c4a6b6958703c Mon Sep 17 00:00:00 2001 From: Mmx233 Date: Wed, 2 Mar 2022 22:19:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 7 +++++-- util/log.go | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 7a4f6f7..df3a5fe 100644 --- a/main.go +++ b/main.go @@ -4,15 +4,18 @@ import ( "github.com/Mmx233/BitSrunLoginGo/controllers" "github.com/Mmx233/BitSrunLoginGo/global" "github.com/Mmx233/BitSrunLoginGo/util" + "log" ) func main() { - util.Log.Init( + if e := util.Log.Init( global.Config.Settings.Debug.Enable, global.Config.Settings.Debug.WriteLog, true, global.Config.Settings.Debug.LogPath, - ) + ); e != nil { + log.Fatalln("初始化日志失败: ", e) + } defer util.Log.CatchRecover() if global.Flags.RunningDaemon { diff --git a/util/log.go b/util/log.go index bb2cfb6..46e531a 100644 --- a/util/log.go +++ b/util/log.go @@ -6,6 +6,7 @@ import ( "log" "os" "runtime" + "strings" "time" ) @@ -19,11 +20,17 @@ type loG struct { var Log loG -func (c *loG) Init(debug, logFile, outPut bool, path string) { +func (c *loG) Init(debug, logFile, outPut bool, path string) error { c.Debug = debug c.WriteFile = logFile c.OutPut = outPut + + //日志路径初始化与处理 + if !strings.HasSuffix(path, "/") { + path += "/" + } c.Path = path + return os.MkdirAll(path, os.ModePerm) } func (c *loG) time() string {