forked from golang/hotime
optimize log tool
This commit is contained in:
parent
df07afb744
commit
770f0a94c9
@ -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 {
|
if that.Error.GetError() == nil {
|
||||||
var configByte bytes.Buffer
|
var configByte bytes.Buffer
|
||||||
|
|
||||||
err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t")
|
err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t")
|
||||||
//判断配置文件是否序列有变化有则修改配置,五则不变
|
//判断配置文件是否序列有变化,有则修改配置,无则不变
|
||||||
//fmt.Println(len(btes))
|
//fmt.Println(len(btes))
|
||||||
if len(btes) != 0 && configByte.String() == string(btes) {
|
if len(btes) != 0 && configByte.String() == string(btes) {
|
||||||
return
|
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则停止传输
|
// SetConnectListener 连接判断,返回true继续传输至控制层,false则停止传输
|
||||||
@ -331,7 +333,7 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
that.crossDomain(&context)
|
that.crossDomain(&context)
|
||||||
//是否展示日志
|
//是否展示日志
|
||||||
if that.WebConnectLog != nil {
|
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暂停
|
//访问拦截true继续false暂停
|
||||||
|
@ -52,9 +52,9 @@ func main() {
|
|||||||
"app": hotime.Proj{
|
"app": hotime.Proj{
|
||||||
"index": hotime.Ctr{
|
"index": hotime.Ctr{
|
||||||
"test": func(this *hotime.Context) {
|
"test": func(this *hotime.Context) {
|
||||||
fmt.Println(this.Db.GetTag())
|
//fmt.Println(this.Db.GetTag())
|
||||||
this.Application.Log.Error("dasdasdas")
|
//this.Application.Log.Error("dasdasdas")
|
||||||
this.Log.Error("dadasdasd")
|
//this.Log.Error("dadasdasd")
|
||||||
//x:=this.Db.Action(func(db hotime.HoTimeDB) bool {
|
//x:=this.Db.Action(func(db hotime.HoTimeDB) bool {
|
||||||
//
|
//
|
||||||
// db.Insert("user",hotime.Map{"unickname":"dasdas"})
|
// db.Insert("user",hotime.Map{"unickname":"dasdas"})
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(function() {
|
$(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) {
|
ws.onmessage = function(e) {
|
||||||
|
|
||||||
$('<li>').text(e.data).appendTo($ul);
|
$('<li>').text(e.data).appendTo($ul);
|
||||||
|
@ -21,7 +21,6 @@ func GetLog(path string, showCodeLine bool) *log.Logger {
|
|||||||
loger := log.New()
|
loger := log.New()
|
||||||
loger.SetFormatter(&log.TextFormatter{})
|
loger.SetFormatter(&log.TextFormatter{})
|
||||||
loger.AddHook(&hook)
|
loger.AddHook(&hook)
|
||||||
loger.Print("dasdasdas")
|
|
||||||
return loger
|
return loger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user