diff --git a/server/event.go b/server/event.go index 8255592..3b70bb7 100644 --- a/server/event.go +++ b/server/event.go @@ -3,6 +3,8 @@ package server import ( "go.uber.org/zap" "minotaur/utils/log" + "minotaur/utils/runtimes" + "reflect" ) type ConnectionReceivePacketEventHandle func(conn *Conn, packet []byte) @@ -22,6 +24,7 @@ func (slf *event) RegConnectionClosedEvent(handle ConnectionClosedEventHandle) { panic(ErrNetworkIncompatibleHttp) } 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) { @@ -36,6 +39,7 @@ func (slf *event) RegConnectionOpenedEvent(handle ConnectionOpenedEventHandle) { panic(ErrNetworkIncompatibleHttp) } 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) { @@ -50,6 +54,7 @@ func (slf *event) RegConnectionReceivePacketEvent(handle ConnectionReceivePacket panic(ErrNetworkIncompatibleHttp) } 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) { diff --git a/utils/runtimes/runtime.go b/utils/runtimes/runtime.go new file mode 100644 index 0000000..b39dc81 --- /dev/null +++ b/utils/runtimes/runtime.go @@ -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() +}