上传网关日志优化

This commit is contained in:
liwei1dao 2022-09-14 11:56:54 +08:00
parent 7de65b5f79
commit bfb6e41284
4 changed files with 26 additions and 6 deletions

View File

@ -42,6 +42,7 @@ type (
Fatal(msg string, args ...Field)
Panic(msg string, args ...Field)
}
ILogger interface {
SetName(name string)
Enabled(lvl Loglevel) bool

View File

@ -257,7 +257,7 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
servicePath = rule
}
} else {
this.gateway.Errorf("messageDistribution rule is empty!")
this.gateway.Error("messageDistribution rule is empty!")
return
}
} else {
@ -266,19 +266,31 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
}
}
stime := time.Now()
this.gateway.Debugf("agent:%s uId:%s MessageDistribution req:%v", this.sessionId, this.uId, req)
if len(serviceTag) == 0 {
if err = this.gateway.Service().RpcCall(context.Background(), servicePath, string(comm.Rpc_GatewayRoute), req, reply); err != nil {
this.gateway.Errorf("agent:%s uId:%s MessageDistribution err:%v", this.sessionId, this.uId, err)
this.gateway.Error("[UserResponse]",
log.Field{Key: "uid", Value: this.uId},
log.Field{Key: "req", Value: req},
log.Field{Key: "err", Value: err},
)
return
}
} else { //跨集群调用
if err = this.gateway.Service().AcrossClusterRpcCall(context.Background(), serviceTag, servicePath, string(comm.Rpc_GatewayRoute), req, reply); err != nil {
this.gateway.Errorf("agent:%s uId:%s MessageDistribution err:%v", this.sessionId, this.uId, err)
this.gateway.Error("[UserResponse]",
log.Field{Key: "uid", Value: this.uId},
log.Field{Key: "req", Value: req},
log.Field{Key: "err", Value: err},
)
return
}
}
this.gateway.Debugf("agent:%s uId:%s MessageDistribution t:%v reply:%v", this.sessionId, this.uId, time.Since(stime).Milliseconds(), reply)
this.gateway.Debug("[UserResponse]",
log.Field{Key: "uid", Value: this.uId},
log.Field{Key: "t", Value: time.Since(stime).Milliseconds()},
log.Field{Key: "req", Value: req},
log.Field{Key: "reply", Value: reply},
)
if reply.Code != pb.ErrorCode_Success {
data, _ := anypb.New(&pb.NotifyErrorNotifyPush{
ReqMainType: msg.MainType,

View File

@ -24,7 +24,7 @@ type (
// IGateway 网关模块 接口定义
IGateway interface {
core.IModule
log.Ilogf
log.ILogger
Service() base.IRPCXService
CrossServiceTag() string
Connect(a IAgent)

View File

@ -107,6 +107,13 @@ func (this *Gateway) GetMsgDistribute(msgmid, msguid string) (rule string, ok bo
}
//日志
func (this *Gateway) Enabled(lvl log.Loglevel) bool {
return this.options.GetLog().Enabled(lvl)
}
func (this *Gateway) SetName(name string) {
this.options.GetLog().SetName(name)
}
//日志接口
func (this *Gateway) Debug(msg string, args ...log.Field) {
this.options.GetLog().Debug(msg, args...)