服务器事件日志优化
This commit is contained in:
parent
ba0b9f7508
commit
644c520454
|
@ -3,6 +3,8 @@ package server
|
||||||
import (
|
import (
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"minotaur/utils/log"
|
"minotaur/utils/log"
|
||||||
|
"minotaur/utils/runtimes"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConnectionReceivePacketEventHandle func(conn *Conn, packet []byte)
|
type ConnectionReceivePacketEventHandle func(conn *Conn, packet []byte)
|
||||||
|
@ -22,6 +24,7 @@ func (slf *event) RegConnectionClosedEvent(handle ConnectionClosedEventHandle) {
|
||||||
panic(ErrNetworkIncompatibleHttp)
|
panic(ErrNetworkIncompatibleHttp)
|
||||||
}
|
}
|
||||||
slf.connectionClosedEventHandles = append(slf.connectionClosedEventHandles, handle)
|
slf.connectionClosedEventHandles = append(slf.connectionClosedEventHandles, handle)
|
||||||
|
log.Info("Server", zap.String("RegEvent", runtimes.CurrentRunningFuncName()), zap.String("handle", reflect.TypeOf(handle).String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *event) OnConnectionClosedEvent(conn *Conn) {
|
func (slf *event) OnConnectionClosedEvent(conn *Conn) {
|
||||||
|
@ -36,6 +39,7 @@ func (slf *event) RegConnectionOpenedEvent(handle ConnectionOpenedEventHandle) {
|
||||||
panic(ErrNetworkIncompatibleHttp)
|
panic(ErrNetworkIncompatibleHttp)
|
||||||
}
|
}
|
||||||
slf.connectionOpenedEventHandles = append(slf.connectionOpenedEventHandles, handle)
|
slf.connectionOpenedEventHandles = append(slf.connectionOpenedEventHandles, handle)
|
||||||
|
log.Info("Server", zap.String("RegEvent", runtimes.CurrentRunningFuncName()), zap.String("handle", reflect.TypeOf(handle).String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *event) OnConnectionOpenedEvent(conn *Conn) {
|
func (slf *event) OnConnectionOpenedEvent(conn *Conn) {
|
||||||
|
@ -50,6 +54,7 @@ func (slf *event) RegConnectionReceivePacketEvent(handle ConnectionReceivePacket
|
||||||
panic(ErrNetworkIncompatibleHttp)
|
panic(ErrNetworkIncompatibleHttp)
|
||||||
}
|
}
|
||||||
slf.connectionReceivePacketEventHandles = append(slf.connectionReceivePacketEventHandles, handle)
|
slf.connectionReceivePacketEventHandles = append(slf.connectionReceivePacketEventHandles, handle)
|
||||||
|
log.Info("Server", zap.String("RegEvent", runtimes.CurrentRunningFuncName()), zap.String("handle", reflect.TypeOf(handle).String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *event) OnConnectionReceivePacketEvent(conn *Conn, packet []byte) {
|
func (slf *event) OnConnectionReceivePacketEvent(conn *Conn, packet []byte) {
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package runtimes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CurrentRunningFuncName 获取正在运行的函数名
|
||||||
|
func CurrentRunningFuncName(skip ...int) string {
|
||||||
|
pc := make([]uintptr, 1)
|
||||||
|
var s = 2
|
||||||
|
if len(skip) > 0 {
|
||||||
|
s += skip[0]
|
||||||
|
}
|
||||||
|
runtime.Callers(s, pc)
|
||||||
|
f := runtime.FuncForPC(pc[0])
|
||||||
|
return f.Name()
|
||||||
|
}
|
Loading…
Reference in New Issue