From 770f0a94c9b7408ac22f5237bc8cd672cb0ae4a1 Mon Sep 17 00:00:00 2001 From: hoteas Date: Tue, 25 May 2021 05:28:56 +0800 Subject: [PATCH] optimize log tool --- application.go | 14 ++++++++------ example/main.go | 6 +++--- example/tpt/index.html | 2 +- log/logrus.go | 1 - 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/application.go b/application.go index 92d3612..5b18446 100644 --- a/application.go +++ b/application.go @@ -222,12 +222,18 @@ func (that *Application) SetConfig(configPath ...string) { } + that.Log = GetLog(that.Config.GetString("logFile"), true) + + if that.Config.GetBool("webConnectLogShow") { + that.WebConnectLog = GetLog(that.Config.GetString("webConnectLogFile"), false) + } + //文件如果损坏则不写入配置防止配置文件数据丢失 if that.Error.GetError() == nil { var configByte bytes.Buffer err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t") - //判断配置文件是否序列有变化有则修改配置,五则不变 + //判断配置文件是否序列有变化,有则修改配置,无则不变 //fmt.Println(len(btes)) if len(btes) != 0 && configByte.String() == string(btes) { return @@ -245,10 +251,6 @@ func (that *Application) SetConfig(configPath ...string) { } - that.Log = GetLog(that.Config.GetString("logFile"), true) - if that.Config.GetBool("webConnectLogShow") { - that.WebConnectLog = GetLog(that.Config.GetString("webConnectLogFile"), false) - } } // SetConnectListener 连接判断,返回true继续传输至控制层,false则停止传输 @@ -331,7 +333,7 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) { that.crossDomain(&context) //是否展示日志 if that.WebConnectLog != nil { - that.WebConnectLog.Infoln(Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":")) + " " + context.HandlerStr) + that.WebConnectLog.Infoln(Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":")), context.Req.Method, context.HandlerStr) } //访问拦截true继续false暂停 diff --git a/example/main.go b/example/main.go index cde3eaa..d347624 100644 --- a/example/main.go +++ b/example/main.go @@ -52,9 +52,9 @@ func main() { "app": hotime.Proj{ "index": hotime.Ctr{ "test": func(this *hotime.Context) { - fmt.Println(this.Db.GetTag()) - this.Application.Log.Error("dasdasdas") - this.Log.Error("dadasdasd") + //fmt.Println(this.Db.GetTag()) + //this.Application.Log.Error("dasdasdas") + //this.Log.Error("dadasdasd") //x:=this.Db.Action(func(db hotime.HoTimeDB) bool { // // db.Insert("user",hotime.Map{"unickname":"dasdas"}) diff --git a/example/tpt/index.html b/example/tpt/index.html index 15b5748..74b846e 100644 --- a/example/tpt/index.html +++ b/example/tpt/index.html @@ -7,7 +7,7 @@