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

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暂停

View File

@ -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"})

View File

@ -7,7 +7,7 @@
<script>
$(function() {
var ws = new WebSocket("ws://localhost:8080/app/index/websocket");
var ws = new WebSocket("ws://localhost:80/app/index/websocket");
ws.onmessage = function(e) {
$('<li>').text(e.data).appendTo($ul);

View File

@ -21,7 +21,6 @@ func GetLog(path string, showCodeLine bool) *log.Logger {
loger := log.New()
loger.SetFormatter(&log.TextFormatter{})
loger.AddHook(&hook)
loger.Print("dasdasdas")
return loger
}