Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/zinx_logger/server/my_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ func (l *MyLogger) DebugFX(ctx context.Context, format string, v ...interface{})
fmt.Println(ctx)
fmt.Printf(format, v...)
}

func (l *MyLogger) DebugEnabled() bool {
return true
}
3 changes: 3 additions & 0 deletions ziface/ilogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ type ILogger interface {
InfoFX(ctx context.Context, format string, v ...interface{})
ErrorFX(ctx context.Context, format string, v ...interface{})
DebugFX(ctx context.Context, format string, v ...interface{})

// 此处增加了 interface 定义,可能会导致原有第三方实现无法通过编译
DebugEnabled() bool
}
4 changes: 4 additions & 0 deletions zlog/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func (log *zinxDefaultLog) DebugFX(ctx context.Context, format string, v ...inte
StdZinxLog.Debugf(format, v...)
}

func (log *zinxDefaultLog) DebugEnabled() bool {
return StdZinxLog.DebugEnabled()
}

func SetLogger(newlog ziface.ILogger) {
zLogInstance = newlog
}
Expand Down
4 changes: 4 additions & 0 deletions zlog/logger_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ func (log *ZinxLoggerCore) SetLogLevel(logLevel int) {
log.isolationLevel = logLevel
}

func (log *ZinxLoggerCore) DebugEnabled() bool {
return log.isolationLevel == LogDebug
}

// Convert an integer to a fixed-length string, where the width of the string should be greater than 0
// Ensure that the buffer has sufficient capacity
// (将一个整形转换成一个固定长度的字符串,字符串宽度应该是大于0的
Expand Down
4 changes: 4 additions & 0 deletions zlog/stdzlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func Stack(v ...interface{}) {
StdZinxLog.Stack(v...)
}

func DebugEnabled() bool {
return StdZinxLog.DebugEnabled()
}

func init() {
// Since the StdZinxLog object wraps all output methods with an extra layer, the call depth is one more than a normal logger object
// The call depth of a regular zinxLogger object is 2, and the call depth of StdZinxLog is 3
Expand Down
8 changes: 6 additions & 2 deletions znet/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ func (c *Connection) StartReader() {
zlog.Ins().ErrorF("read msg head [read datalen=%d], error = %s", n, err)
return
}
zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(buffer[0:n]))
if zlog.Ins().DebugEnabled() {
zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(buffer[0:n]))
}

// If normal data is read from the peer, update the heartbeat detection Active state
// (正常读取到对端数据,更新心跳检测Active状态)
Expand All @@ -269,7 +271,9 @@ func (c *Connection) StartReader() {
continue
}
for _, bytes := range bufArrays {
// zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(bytes))
//if zlog.Ins().DebugEnabled() {
// zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(buffer[0:n]))
//}
msg := zpack.NewMessage(uint32(len(bytes)), bytes)
// Get the current client's Request data
// (得到当前客户端请求的Request数据)
Expand Down
8 changes: 6 additions & 2 deletions znet/kcp_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ func (c *KcpConnection) StartReader() {
zlog.Ins().ErrorF("read msg head [read datalen=%d], error = %s", n, err)
return
}
zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(buffer[0:n]))
if zlog.Ins().DebugEnabled() {
zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(buffer[0:n]))
}

// If normal data is read from the peer, update the heartbeat detection Active state
// (正常读取到对端数据,更新心跳检测Active状态)
Expand All @@ -254,7 +256,9 @@ func (c *KcpConnection) StartReader() {
continue
}
for _, bytes := range bufArrays {
// zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(bytes))
//if zlog.Ins().DebugEnabled() {
// zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(buffer[0:n]))
//}
msg := zpack.NewMessage(uint32(len(bytes)), bytes)
// Get the current client's Request data
// (得到当前客户端请求的Request数据)
Expand Down
4 changes: 3 additions & 1 deletion znet/msghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ func (mh *MsgHandle) SendMsgToTaskQueue(request ziface.IRequest) {
// zlog.Ins().DebugF("Add ConnID=%d request msgID=%d to workerID=%d", request.GetConnection().GetConnID(), request.GetMsgID(), workerID)
// Send the request message to the task queue
mh.TaskQueue[workerID] <- request
zlog.Ins().DebugF("SendMsgToTaskQueue-->%s", hex.EncodeToString(request.GetData()))
if zlog.Ins().DebugEnabled() {
zlog.Ins().DebugF("SendMsgToTaskQueue-->%s", hex.EncodeToString(request.GetData()))
}
}

// doFuncHandler handles functional requests (执行函数式请求)
Expand Down
8 changes: 6 additions & 2 deletions znet/ws_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ func (c *WsConnection) StartReader() {
zlog.Ins().ErrorF("read msg head [read datalen=%d], error = %s", n, err.Error())
return
}
zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(buffer[0:n]))
if zlog.Ins().DebugEnabled() {
zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(buffer[0:n]))
}

// Update the Active status of heartbeat detection normally after reading data from the peer.
// (正常读取到对端数据,更新心跳检测Active状态)
Expand All @@ -253,7 +255,9 @@ func (c *WsConnection) StartReader() {
continue
}
for _, bytes := range bufArrays {
zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(bytes))
if zlog.Ins().DebugEnabled() {
zlog.Ins().DebugF("read buffer %s \n", hex.EncodeToString(bytes))
}
msg := zpack.NewMessage(uint32(len(bytes)), bytes)
// Get the Request data requested by the current client.
// (得到当前客户端请求的Request数据)
Expand Down
Loading