From 1a5f02ed31c2297a59264104246fc98676e170af Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 21 Dec 2022 21:09:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lego/sys/log/logger.go | 12 +++++++++++- modules/chat/api_send.go | 15 +++------------ modules/gateway/agent.go | 6 +++--- services/cmd/main.go | 19 +++++++++++++++---- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/lego/sys/log/logger.go b/lego/sys/log/logger.go index a9cac510f..f7e5d3da0 100644 --- a/lego/sys/log/logger.go +++ b/lego/sys/log/logger.go @@ -53,10 +53,20 @@ type Logger struct { } func (this *Logger) Clone(name string, skip int) ILogger { + _name := "" + if name == "" { + _name = this.name + } else { + if this.name == "" { + _name = name + } else { + _name = fmt.Sprintf("%s:%s", this.name, name) + } + } return &Logger{ config: this.config, formatter: this.formatter, - name: fmt.Sprintf("%s:%s", this.name, name), + name: _name, out: this.out, level: this.level, addCaller: this.addCaller, diff --git a/modules/chat/api_send.go b/modules/chat/api_send.go index 6fc29d3a5..507ed5748 100644 --- a/modules/chat/api_send.go +++ b/modules/chat/api_send.go @@ -74,10 +74,7 @@ func (this *apiComp) Send(session comm.IUserSession, req *pb.ChatSendReq) (code if msg.Ctype == pb.ChatType_Text { //过滤敏感词 msg.Content = wordfilter.Replace(msg.Content, '*') } - if err = this.module.modelChat.sendChatToWorld(msg, max_chat); err != nil { - code = pb.ErrorCode_DBError - return - } + go this.module.modelChat.sendChatToWorld(msg, max_chat) this.module.ModuleRtask.SendToRtask(session, comm.Rtype62, 1) //随机任务 // if _, err = this.service.AcrossClusterRpcGo( @@ -95,10 +92,7 @@ func (this *apiComp) Send(session comm.IUserSession, req *pb.ChatSendReq) (code msg.Content = wordfilter.Replace(msg.Content, '*') } msg.UnionId = req.TargetId - if err = this.module.modelChat.sendChatToUnion(msg, max_chat); err != nil { - code = pb.ErrorCode_DBError - return - } + go this.module.modelChat.sendChatToUnion(msg, max_chat) break case pb.ChatChannel_Private: if msg.Ctype == pb.ChatType_Text { //过滤敏感词 @@ -121,10 +115,7 @@ func (this *apiComp) Send(session comm.IUserSession, req *pb.ChatSendReq) (code } msg.ChannelId = userexpand.Chatchannel //指定频道 - if err = this.module.modelChat.sendChatToCrossServer(msg, max_chat); err != nil { - code = pb.ErrorCode_DBError - return - } + go this.module.modelChat.sendChatToCrossServer(msg, max_chat) this.module.ModuleRtask.SendToRtask(session, comm.Rtype106, 1) break default: diff --git a/modules/gateway/agent.go b/modules/gateway/agent.go index 43de36d6a..44e9f4b7a 100644 --- a/modules/gateway/agent.go +++ b/modules/gateway/agent.go @@ -287,7 +287,7 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) { log.Field{Key: "serviceTag", Value: serviceTag}, log.Field{Key: "servicePath", Value: servicePath}, log.Field{Key: "servicePath", Value: servicePath}, - log.Field{Key: "req", Value: req.String()}, + log.Field{Key: "req", Value: fmt.Sprintf("%s:%s %v", req.MainType, req.SubType, req.Message.String())}, log.Field{Key: "err", Value: err.Error()}, ) return @@ -298,7 +298,7 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) { log.Field{Key: "uid", Value: this.uId}, log.Field{Key: "serviceTag", Value: serviceTag}, log.Field{Key: "servicePath", Value: servicePath}, - log.Field{Key: "req", Value: req.String()}, + log.Field{Key: "req", Value: fmt.Sprintf("%s:%s %v", req.MainType, req.SubType, req.Message.String())}, log.Field{Key: "err", Value: err.Error()}, ) return @@ -307,7 +307,7 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) { this.gateway.Debug("[UserResponse]", log.Field{Key: "t", Value: time.Since(stime).Milliseconds()}, log.Field{Key: "uid", Value: this.uId}, - log.Field{Key: "req", Value: req.String()}, + log.Field{Key: "req", Value: fmt.Sprintf("%s:%s %v", req.MainType, req.SubType, req.Message.String())}, log.Field{Key: "reply", Value: reply.String()}, ) if reply.Code != pb.ErrorCode_Success { diff --git a/services/cmd/main.go b/services/cmd/main.go index af32b13fa..07c879b5b 100644 --- a/services/cmd/main.go +++ b/services/cmd/main.go @@ -29,6 +29,7 @@ var ( gmpath string //服务列表下标 crosspath string //服务列表下标 sid string //服务列表下标 + onelog bool //日志路径 ) var confCmd = &cobra.Command{ Use: "conf", @@ -78,6 +79,7 @@ func init() { RootCmd.PersistentFlags().StringVarP(&gmpath, "gm", "g", "./gm.json", "游戏区服配置") RootCmd.PersistentFlags().StringVarP(&crosspath, "cross", "c", "./cross.json", "游戏跨服配置") RootCmd.PersistentFlags().StringVarP(&sid, "sid", "i", "", "区服id") + RootCmd.PersistentFlags().BoolVarP(&onelog, "log", "l", false, "输出日志") RootCmd.AddCommand(confCmd, startCmd, stopCmd, restart) } @@ -319,11 +321,20 @@ func convertServiceSttings(config *comm.GameConfig, id int, stype string, ip str err = fmt.Errorf("服务类型异常 stype:%s", sseting.Type) return } - sseting.Sys["log"] = map[string]interface{}{ - "FileName": fmt.Sprintf("./log/%s.log", sseting.Id), - "Loglevel": config.Loglevel, - "MaxAgeTime": config.MaxAgeTime, + if !onelog { + sseting.Sys["log"] = map[string]interface{}{ + "FileName": fmt.Sprintf("./log/%s.log", sseting.Id), + "Loglevel": config.Loglevel, + "MaxAgeTime": config.MaxAgeTime, + } + } else { + sseting.Sys["log"] = map[string]interface{}{ + "FileName": fmt.Sprintf("./log/%s.log", config.AreaId), + "Loglevel": config.Loglevel, + "MaxAgeTime": config.MaxAgeTime, + } } + sseting.Sys["configure"] = map[string]interface{}{ "ConfigurePath": "./json", "TimestampFile": "./timestamp.text",