optimize log tool

This commit is contained in:
hoteas
2021-05-25 05:28:56 +08:00
parent df07afb744
commit 770f0a94c9
4 changed files with 12 additions and 11 deletions
+8 -6
View File
@@ -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暂停