From 2b2df18e73957bad1ea3fcdb96546539bbbb926f Mon Sep 17 00:00:00 2001 From: Mmx <1624045573@qq.com> Date: Sat, 29 May 2021 11:43:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=85=BC=E5=AE=B9windows=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、修复文件名带”:“导致的windows无日志问题 2、日志添加时间戳 3、新增恐慌详细日志捕获 --- Util/log.go | 7 +++++-- main.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Util/log.go b/Util/log.go index 34cf3a6..0b9d5f5 100644 --- a/Util/log.go +++ b/Util/log.go @@ -25,13 +25,16 @@ func (*loG) WriteLog(name string, a ...interface{}) { default: t = fmt.Sprint(v) } - _ = File.Add(name, t) + err := File.Add(name, fmt.Sprintf(time.Now().Format("2006/01/02 15:04:05 "))+t) + if err != nil { + log.Println("Log error: ", err) + } } } func (c *loG) genTimeStamp() { if c.timeStamp == "" { - c.timeStamp = time.Now().Format("2006.01.02-15:04:05") + c.timeStamp = time.Now().Format("2006.01.02-15.04.05") } } diff --git a/main.go b/main.go index 166868a..462bfa8 100644 --- a/main.go +++ b/main.go @@ -6,10 +6,20 @@ import ( "Mmx/Util" "encoding/json" "fmt" + "os" + "runtime" "time" ) func main() { + defer func() { + if e := recover(); e != nil { + Util.Log.Println(e) + var buf [4096]byte + Util.Log.Println(string(buf[:runtime.Stack(buf[:], false)])) + os.Exit(1) + } + }() Util.Log.Println("Step0: 检查状态…") G := Global.Config.Generate()