日志logFields

This commit is contained in:
wh_zcy 2022-11-15 19:34:31 +08:00
parent 0e6ce53580
commit af438aaba0
38 changed files with 247 additions and 224 deletions

View File

@ -10,11 +10,8 @@ var AllLevels = []Loglevel{
}
type (
Field struct {
Key string
Value interface{}
}
Fields []Field
Fields map[string]interface{}
Ilogf interface {
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
@ -34,13 +31,13 @@ type (
Panicln(args ...interface{})
}
ILog interface {
Debug(msg string, args ...Field)
Info(msg string, args ...Field)
Print(msg string, args ...Field)
Warn(msg string, args ...Field)
Error(msg string, args ...Field)
Fatal(msg string, args ...Field)
Panic(msg string, args ...Field)
Debug(msg string, args Fields)
Info(msg string, args Fields)
Print(msg string, args Fields)
Warn(msg string, args Fields)
Error(msg string, args Fields)
Fatal(msg string, args Fields)
Panic(msg string, args Fields)
}
ILogger interface {
@ -80,23 +77,23 @@ func NewSys(opt ...Option) (sys ISys, err error) {
func Clone(name string, skip int) ILogger {
return defsys.Clone(name, skip)
}
func Debug(msg string, args ...Field) {
defsys.Debug(msg, args...)
func Debug(msg string, args Fields) {
defsys.Debug(msg, args)
}
func Info(msg string, args ...Field) {
defsys.Info(msg, args...)
func Info(msg string, args Fields) {
defsys.Info(msg, args)
}
func Warn(msg string, args ...Field) {
defsys.Warn(msg, args...)
func Warn(msg string, args Fields) {
defsys.Warn(msg, args)
}
func Error(msg string, args ...Field) {
defsys.Error(msg, args...)
func Error(msg string, args Fields) {
defsys.Error(msg, args)
}
func Fatal(msg string, args ...Field) {
defsys.Fatal(msg, args...)
func Fatal(msg string, args Fields) {
defsys.Fatal(msg, args)
}
func Panic(msg string, args ...Field) {
defsys.Panic(msg, args...)
func Panic(msg string, args Fields) {
defsys.Panic(msg, args)
}
func Debugf(format string, args ...interface{}) {
defsys.Debugf(format, args...)

View File

@ -14,7 +14,7 @@ var (
_cePool = sync.Pool{New: func() interface{} {
// Pre-allocate some space for cores.
return &Entry{
Data: make(Fields, 0, 6),
Data: make(map[string]interface{}),
}
}}
)
@ -91,31 +91,29 @@ func (entry *Entry) reset() {
entry.Caller.Function = ""
entry.Caller.Stack = ""
entry.Err = ""
entry.Data = entry.Data[:0]
entry.Data = make(map[string]interface{})
}
func (entry *Entry) WithFields(fields ...Field) {
if cap(entry.Data) < len(fields) {
entry.Data = make(Fields, 0, cap(entry.Data)+len(fields))
}
func (entry *Entry) WithFields(fields Fields) {
fieldErr := entry.Err
for _, v := range fields {
for k, v := range fields {
isErrField := false
if t := reflect.TypeOf(v.Value); t != nil {
if t := reflect.TypeOf(v); t != nil {
switch {
case t.Kind() == reflect.Func, t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Func:
isErrField = true
}
}
if isErrField {
tmp := fmt.Sprintf("can not add field %q", v.Key)
tmp := fmt.Sprintf("can not add field %q", k)
if fieldErr != "" {
fieldErr = entry.Err + ", " + tmp
} else {
fieldErr = tmp
}
} else {
entry.Data = append(entry.Data, v)
entry.Data[k] = v
}
}
}

View File

@ -9,7 +9,7 @@ import (
var _fieldsPool = sync.Pool{
New: func() interface{} {
return make(Fields, 0, 6)
return make(map[string]interface{})
},
}
@ -18,7 +18,6 @@ func getFields() Fields {
}
func putFields(fields Fields) {
fields = fields[:0]
_fieldsPool.Put(fields)
}

View File

@ -62,14 +62,14 @@ func (this *ConsoleFormatter) Format(config *EncoderConfig, entry *Entry) (*pool
isfirst = false
line.AppendString(entry.Message)
}
for _, v := range entry.Data {
for k, v := range entry.Data {
if !isfirst {
line.AppendString(config.ConsoleSeparator)
}
isfirst = false
line.AppendString(v.Key)
line.AppendString(k)
line.AppendString(":")
writetoline(line, v.Value)
writetoline(line, v)
}
if entry.Caller.Stack != "" && config.StacktraceKey != "" {

View File

@ -68,31 +68,31 @@ func (this *Logger) SetName(name string) {
func (this *Logger) Enabled(lvl Loglevel) bool {
return this.level.Enabled(lvl)
}
func (this *Logger) Debug(msg string, args ...Field) {
this.Log(DebugLevel, msg, args...)
func (this *Logger) Debug(msg string, args Fields) {
this.Log(DebugLevel, msg, args)
}
func (this *Logger) Info(msg string, args ...Field) {
this.Log(InfoLevel, msg, args...)
func (this *Logger) Info(msg string, args Fields) {
this.Log(InfoLevel, msg, args)
}
func (this *Logger) Print(msg string, args ...Field) {
this.Log(InfoLevel, msg, args...)
func (this *Logger) Print(msg string, args Fields) {
this.Log(InfoLevel, msg, args)
}
func (this *Logger) Warn(msg string, args ...Field) {
this.Log(WarnLevel, msg, args...)
func (this *Logger) Warn(msg string, args Fields) {
this.Log(WarnLevel, msg, args)
}
func (this *Logger) Error(msg string, args ...Field) {
this.Log(ErrorLevel, msg, args...)
func (this *Logger) Error(msg string, args Fields) {
this.Log(ErrorLevel, msg, args)
}
func (this *Logger) Panic(msg string, args ...Field) {
this.Log(PanicLevel, msg, args...)
func (this *Logger) Panic(msg string, args Fields) {
this.Log(PanicLevel, msg, args)
}
func (this *Logger) Fatal(msg string, args ...Field) {
this.Log(FatalLevel, msg, args...)
func (this *Logger) Fatal(msg string, args Fields) {
this.Log(FatalLevel, msg, args)
os.Exit(1)
}
func (this *Logger) Log(level Loglevel, msg string, args ...Field) {
func (this *Logger) Log(level Loglevel, msg string, args Fields) {
if this.level.Enabled(level) {
this.log(level, msg, args...)
this.logWithFields(level, msg, args)
}
}
func (this *Logger) Debugf(format string, args ...interface{}) {
@ -150,8 +150,8 @@ func (this *Logger) Logln(level Loglevel, args ...interface{}) {
}
}
func (this *Logger) log(level Loglevel, msg string, args ...Field) {
entry := this.check(level, msg, args...)
func (this *Logger) logWithFields(level Loglevel, msg string, args Fields) {
entry := this.checkWithFields(level, msg, args)
this.write(entry)
if level <= PanicLevel {
panic(entry)
@ -159,13 +159,28 @@ func (this *Logger) log(level Loglevel, msg string, args ...Field) {
putEntry(entry)
}
func (this *Logger) check(level Loglevel, msg string, args ...Field) (entry *Entry) {
func (this *Logger) log(level Loglevel, msg string) {
entry := this.check(level, msg)
this.write(entry)
if level <= PanicLevel {
panic(entry)
}
putEntry(entry)
}
func (this *Logger) checkWithFields(level Loglevel, msg string, args Fields) (entry *Entry) {
e := this.check(level, msg)
e.WithFields(args)
return e
}
func (this *Logger) check(level Loglevel, msg string) (entry *Entry) {
entry = getEntry()
entry.Name = this.name
entry.Time = time.Now()
entry.Level = level
entry.Message = msg
entry.WithFields(args...)
// entry.WithFields(args)
addStack := this.addStack.Enabled(level)
addCaller := this.addCaller.Enabled(level)
if !addCaller && !addStack {

View File

@ -14,7 +14,7 @@ type TestData struct {
}
func (this *TestData) Log() {
sys.Error("妈妈咪呀!")
sys.Errorln("妈妈咪呀!")
}
var sys log.ISys
@ -39,6 +39,7 @@ func Test_sys(t *testing.T) {
//性能测试
func Benchmark_Ability(b *testing.B) {
for i := 0; i < b.N; i++ { //use b.N for looping
sys.Error("妈妈咪呀!")
// sys.Errorln("妈妈咪呀!")
sys.Error("测试", log.Fields{"a":1,"b":2})
}
}

View File

@ -25,39 +25,39 @@ func (this *Turnlog) Enabled(lvl Loglevel) bool {
return false
}
}
func (this *Turnlog) Debug(msg string, args ...Field) {
func (this *Turnlog) Debug(msg string, args Fields) {
if this.isturnon && this.log != nil {
this.log.Debug(msg, args...)
this.log.Debug(msg, args)
}
}
func (this *Turnlog) Info(msg string, args ...Field) {
func (this *Turnlog) Info(msg string, args Fields) {
if this.isturnon && this.log != nil {
this.log.Info(msg, args...)
this.log.Info(msg, args)
}
}
func (this *Turnlog) Print(msg string, args ...Field) {
func (this *Turnlog) Print(msg string, args Fields) {
if this.isturnon && this.log != nil {
this.log.Print(msg, args...)
this.log.Print(msg, args)
}
}
func (this *Turnlog) Warn(msg string, args ...Field) {
func (this *Turnlog) Warn(msg string, args Fields) {
if this.isturnon && this.log != nil {
this.log.Warn(msg, args...)
this.log.Warn(msg, args)
}
}
func (this *Turnlog) Error(msg string, args ...Field) {
func (this *Turnlog) Error(msg string, args Fields) {
if this.log != nil {
this.log.Error(msg, args...)
this.log.Error(msg, args)
}
}
func (this *Turnlog) Panic(msg string, args ...Field) {
func (this *Turnlog) Panic(msg string, args Fields) {
if this.log != nil {
this.log.Panic(msg, args...)
this.log.Panic(msg, args)
}
}
func (this *Turnlog) Fatal(msg string, args ...Field) {
func (this *Turnlog) Fatal(msg string, args Fields) {
if this.log != nil {
this.log.Fatal(msg, args...)
this.log.Fatal(msg, args)
}
}
func (this *Turnlog) Debugf(format string, args ...interface{}) {

View File

@ -60,7 +60,11 @@ func (this *Selector) Select(ctx context.Context, servicePath, serviceMethod str
} else if leng == 2 {
result := this.ParseRoutRules(service[1])
if len(result) == 0 {
this.log.Error("Select no found any node", log.Field{"stag", this.stag}, log.Field{"servicePath", servicePath}, log.Field{"serviceMethod", serviceMethod}, log.Field{"routrules", routrules})
this.log.Error("Select no found any node", log.Fields{
"stag": this.stag,
"servicePath": servicePath,
"serviceMethod": serviceMethod,
"routrules": routrules})
return ""
}
i := fastrand.Uint32n(uint32(len(result)))

View File

@ -68,6 +68,6 @@ func (this *Arena) OnInstallComp() {
//比赛结算
func (this *Arena) Rpc_ModuleArenaRaceSettlement(ctx context.Context, args *pb.EmptyReq, reply *pb.EmptyResp) {
this.Debug("Rpc_ModuleArenaRaceSettlement", log.Field{Key: "args", Value: args.String()})
this.Debug("Rpc_ModuleArenaRaceSettlement", log.Fields{ "args": args.String()})
this.modelRank.raceSettlement()
}

View File

@ -132,7 +132,7 @@ func (this *configureComp) GetSkillAtk(skillId int32, skillLv int32) (result *cf
}
}
err = fmt.Errorf("no found SkillAtk skillId:%d skillLv%d", skillId, skillLv)
this.module.Error(err.Error())
this.module.Errorln(err.Error())
return
}
@ -147,7 +147,7 @@ func (this *configureComp) GetSkillAfteratk(skillId int32) (result *cfg.GameSkil
} else {
if result, ok = v.(*cfg.GameSkillAfteratk).GetDataMap()[skillId]; !ok {
err = fmt.Errorf("on found SkillAfteratk skillId:%d", skillId)
this.module.Error(err.Error())
this.module.Errorln(err.Error())
}
}
return
@ -164,7 +164,7 @@ func (this *configureComp) GetSkillBuff(skillId int32) (result *cfg.GameSkillBuf
} else {
if result, ok = v.(*cfg.GameSkillBuff).GetDataMap()[skillId]; !ok {
err = fmt.Errorf("on found SkillAfteratk skillId:%d", skillId)
this.module.Error(err.Error())
this.module.Errorln(err.Error())
}
}
return
@ -181,7 +181,7 @@ func (this *configureComp) GetSkillPassive(skillId int32) (result *cfg.GameSkill
} else {
if result, ok = v.(*cfg.GameSkillPassive).GetDataMap()[skillId]; !ok {
err = fmt.Errorf("on found SkillAfteratk skillId:%d", skillId)
this.module.Error(err.Error())
this.module.Errorln(err.Error())
}
}
return

View File

@ -48,7 +48,7 @@ func (this *FightBase) Init() {
/// 开始战斗
func (this *FightBase) StartFight() {
this.fightIng = true
this.Debug("=========开始战斗=========")
this.Debugln("=========开始战斗=========")
//记录战报
com := new(core.ComStartFight)
com.CurWave = 1
@ -72,7 +72,7 @@ func (this *FightBase) BeforeStart() {
/// 触发队长技队长技配置在atk表中触发顺序无所谓
func (this *FightBase) EmitCaptainSkill() {
this.Debug("计算队长技...")
this.Debugln("计算队长技...")
for _, role := range this.roles {
if role.GetData().Captain && role.GetData().CaptainSkillId != 0 {
_skill := role.AddSkill(role.GetData().CaptainSkillId, 1)
@ -129,26 +129,26 @@ func (this *FightBase) Rand(min, max int32) int32 {
//Log-----------------------------------------------------------------------------------------------------------------------
//日志接口
func (this *FightBase) Debug(msg string, args ...log.Field) {
this.options.Log.Debug(msg, args...)
func (this *FightBase) Debug(msg string, args log.Fields) {
this.options.Log.Debug(msg, args)
}
func (this *FightBase) Info(msg string, args ...log.Field) {
this.options.Log.Info(msg, args...)
func (this *FightBase) Info(msg string, args log.Fields) {
this.options.Log.Info(msg, args)
}
func (this *FightBase) Print(msg string, args ...log.Field) {
this.options.Log.Print(msg, args...)
func (this *FightBase) Print(msg string, args log.Fields) {
this.options.Log.Print(msg, args)
}
func (this *FightBase) Warn(msg string, args ...log.Field) {
this.options.Log.Warn(msg, args...)
func (this *FightBase) Warn(msg string, args log.Fields) {
this.options.Log.Warn(msg, args)
}
func (this *FightBase) Error(msg string, args ...log.Field) {
this.options.Log.Error(msg, args...)
func (this *FightBase) Error(msg string, args log.Fields) {
this.options.Log.Error(msg, args)
}
func (this *FightBase) Panic(msg string, args ...log.Field) {
this.options.Log.Panic(msg, args...)
func (this *FightBase) Panic(msg string, args log.Fields) {
this.options.Log.Panic(msg, args)
}
func (this *FightBase) Fatal(msg string, args ...log.Field) {
this.options.Log.Fatal(msg, args...)
func (this *FightBase) Fatal(msg string, args log.Fields) {
this.options.Log.Fatal(msg, args)
}
func (this *FightBase) Debugf(format string, args ...interface{}) {

View File

@ -281,7 +281,7 @@ func (this *modelBattleComp) createMasterRoles(comp, wheel int, fid int32) (capt
} else {
hero := &pb.DBHero{}
if hero = this.module.ModuleHero.CreateMonster(monst.HeroId, monst.Star, v.Lv); hero == nil {
this.module.Error("on found battle req data", log.Field{Key: "HeroId", Value: monst.HeroId})
this.module.Error("on found battle req data", log.Fields{ "HeroId": monst.HeroId})
code = pb.ErrorCode_ReqParameterError
return
} else {

View File

@ -82,7 +82,7 @@ func (this *Chat) OnInstallComp() {
//Event------------------------------------------------------------------------------------------------------------
func (this *Chat) EventUserOffline(session comm.IUserSession) {
if err := this.modelChat.removeCrossChannelMember(session); err != nil {
this.Debug("EventUserOffline:", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "err", Value: err.Error()})
this.Debug("EventUserOffline:", log.Fields{ "uid": session.GetUserId(),"err":err.Error()})
}
}

View File

@ -71,7 +71,7 @@ func (this *Friend) ResetFriend(uid string) {
"received": 0, //奖励状态重置
}
if err := this.modelFriend.Change(uid, zanUpdate); err != nil {
log.Error("resetZanFriend err", log.Field{Key: "err", Value: err})
log.Error("resetZanFriend err", log.Fields{"err": err})
}
// 重置今日友情点
@ -80,7 +80,7 @@ func (this *Friend) ResetFriend(uid string) {
"friendPointOD": 0,
}
if err := this.ModuleUser.ChangeUserExpand(uid, update); err != nil {
log.Error("resetFriend err", log.Field{Key: "err", Value: err})
log.Error("resetFriend err", log.Fields{"err": err})
}
}
@ -100,7 +100,7 @@ func (this *Friend) GetFriendList(uid string) (uids []string) {
}
func (this *Friend) RpcUseAssisHero(ctx context.Context, req *pb.RPCGeneralReqA2, reply *pb.DBHero) error {
this.Debug("Rpc_ModuleFriendUseAssitHero", log.Field{Key: "req", Value: req})
this.Debug("Rpc_ModuleFriendUseAssitHero", log.Fields{"req": req})
hero, err := this.UseAssistHero(req.Param1, req.Param2)
if err != nil {
return err

View File

@ -270,27 +270,20 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
if len(serviceTag) == 0 {
if err = this.gateway.Service().RpcCall(context.Background(), servicePath, string(comm.Rpc_GatewayRoute), req, reply); err != nil {
this.gateway.Error("[UserResponse]",
log.Field{Key: "uid", Value: this.uId},
log.Field{Key: "req", Value: req.String()},
log.Field{Key: "err", Value: err.Error()},
log.Fields{"uid": this.uId, "req": req.String(), "err": err.Error()},
)
return
}
} else { //跨集群调用
if err = this.gateway.Service().AcrossClusterRpcCall(context.Background(), serviceTag, servicePath, string(comm.Rpc_GatewayRoute), req, reply); err != nil {
this.gateway.Error("[UserResponse]",
log.Field{Key: "uid", Value: this.uId},
log.Field{Key: "req", Value: req.String()},
log.Field{Key: "err", Value: err.Error()},
log.Fields{"uid": this.uId, "req": req.String(), "err": err.Error()},
)
return
}
}
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.String()},
log.Field{Key: "reply", Value: reply.String()},
log.Fields{"uid": this.uId, "t": time.Since(stime).Milliseconds(), "req": req.String(), "reply": reply.String()},
)
if reply.Code != pb.ErrorCode_Success {
data, _ := anypb.New(&pb.NotifyErrorNotifyPush{

View File

@ -124,26 +124,26 @@ func (this *Gateway) SetName(name string) {
}
//日志接口
func (this *Gateway) Debug(msg string, args ...log.Field) {
this.options.GetLog().Debug(msg, args...)
func (this *Gateway) Debug(msg string, args log.Fields) {
this.options.GetLog().Debug(msg, args)
}
func (this *Gateway) Info(msg string, args ...log.Field) {
this.options.GetLog().Info(msg, args...)
func (this *Gateway) Info(msg string, args log.Fields) {
this.options.GetLog().Info(msg, args)
}
func (this *Gateway) Print(msg string, args ...log.Field) {
this.options.GetLog().Print(msg, args...)
func (this *Gateway) Print(msg string, args log.Fields) {
this.options.GetLog().Print(msg, args)
}
func (this *Gateway) Warn(msg string, args ...log.Field) {
this.options.GetLog().Warn(msg, args...)
func (this *Gateway) Warn(msg string, args log.Fields) {
this.options.GetLog().Warn(msg, args)
}
func (this *Gateway) Error(msg string, args ...log.Field) {
this.options.GetLog().Error(msg, args...)
func (this *Gateway) Error(msg string, args log.Fields) {
this.options.GetLog().Error(msg, args)
}
func (this *Gateway) Panic(msg string, args ...log.Field) {
this.options.GetLog().Panic(msg, args...)
func (this *Gateway) Panic(msg string, args log.Fields) {
this.options.GetLog().Panic(msg, args)
}
func (this *Gateway) Fatal(msg string, args ...log.Field) {
this.options.GetLog().Fatal(msg, args...)
func (this *Gateway) Fatal(msg string, args log.Fields) {
this.options.GetLog().Fatal(msg, args)
}
func (this *Gateway) Debugf(format string, args ...interface{}) {

View File

@ -84,7 +84,7 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC
if code == pb.ErrorCode_Success { // 成功直接返回
session.SendMsg(string(this.GetType()), "cmd", &pb.GMCmdResp{IsSucc: true})
}
this.Debug("使用bingo命令", log.Field{"uid", session.GetUserId()}, log.Field{"A", datas[0]}, log.Field{"T", datas[1]}, log.Field{"N", int32(num)})
this.Debug("使用bingo命令", log.Fields{"uid": session.GetUserId(), "A": datas[0], "T": datas[1], "N": int32(num)})
} else if len(datas) == 2 && (datas[0] == "mapid") {
module1, err := this.service.GetModule(comm.ModuleMainline)
if err != nil {
@ -97,7 +97,7 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC
}
code = module1.(comm.IMainline).ModifyMainlineData(session.GetUserId(), int32(num))
this.Debug("使用bingo命令", log.Field{"uid", session.GetUserId()}, log.Field{"0", datas[0]}, log.Field{"N", int32(num)})
this.Debug("使用bingo命令", log.Fields{"uid": session.GetUserId(), "0": datas[0], "N": int32(num)})
} else if len(datas) == 2 && (datas[0] == "pataid") {
module1, err := this.service.GetModule(comm.ModulePagoda)
if err != nil {
@ -109,7 +109,7 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC
return
}
code = module1.(comm.IPagoda).ModifyPagodaFloor(session, int32(num))
this.Debug("使用bingo命令:uid = %s ", log.Field{"uid", session.GetUserId()}, log.Field{"0", datas[0]}, log.Field{"N", int32(num)})
this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[0], "N": int32(num)})
} else if len(datas) == 1 && (datas[0] == "Iamyoudad" || datas[0] == "iamyoudad") {
var (
res []*cfg.Gameatn
@ -124,7 +124,7 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC
this.Errorf("资源发放失败,%v", code)
}
}
this.Debugf("使用bingo命令", log.Field{"uid", session.GetUserId()}, datas[0], res)
this.Debugf("使用bingo命令", log.Fields{"uid": session.GetUserId()}, datas[0], res)
} else if len(datas) == 3 && (datas[0] == "worldtask") {
module, err := this.service.GetModule(comm.ModuleWorldtask)
if err != nil {
@ -145,7 +145,7 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC
}
func (this *GM) Rpc_ModuleGMCreateCmd(ctx context.Context, args *pb.RPCGeneralReqA2, reply *pb.EmptyResp) (err error) {
this.Debug("Rpc_ModuleGMCreateCmd", log.Field{Key: "args", Value: args.String()})
this.Debug("Rpc_ModuleGMCreateCmd", log.Fields{"args": args.String()})
if args.Param1 == "" || args.Param2 == "" {
err = errors.New("请求参数错误")
}

View File

@ -227,7 +227,7 @@ func (this *Library) getLibraryByObjID(uid, oid string) *pb.DBLibrary {
}
func (this *Library) Rpc_ModuleFetter(ctx context.Context, args *pb.RPCGeneralReqA2, reply *pb.EmptyResp) (err error) {
this.Debug("Rpc_ModuleFetter", log.Field{Key: "args", Value: args.String()})
this.Debug("Rpc_ModuleFetter", log.Fields{"args": args.String()})
if args.Param1 == "" || args.Param2 == "" {
err = errors.New("请求参数错误")
}

View File

@ -413,26 +413,26 @@ func (this *ModuleBase) GetDBNoduleByUid(uid, tableName string, expired time.Dur
}
//日志接口
func (this *ModuleBase) Debug(msg string, args ...log.Field) {
this.options.GetLog().Debug(msg, args...)
func (this *ModuleBase) Debug(msg string, args log.Fields) {
this.options.GetLog().Debug(msg, args)
}
func (this *ModuleBase) Info(msg string, args ...log.Field) {
this.options.GetLog().Info(msg, args...)
func (this *ModuleBase) Info(msg string, args log.Fields) {
this.options.GetLog().Info(msg, args)
}
func (this *ModuleBase) Print(msg string, args ...log.Field) {
this.options.GetLog().Print(msg, args...)
func (this *ModuleBase) Print(msg string, args log.Fields) {
this.options.GetLog().Print(msg, args)
}
func (this *ModuleBase) Warn(msg string, args ...log.Field) {
this.options.GetLog().Warn(msg, args...)
func (this *ModuleBase) Warn(msg string, args log.Fields) {
this.options.GetLog().Warn(msg, args)
}
func (this *ModuleBase) Error(msg string, args ...log.Field) {
this.options.GetLog().Error(msg, args...)
func (this *ModuleBase) Error(msg string, args log.Fields) {
this.options.GetLog().Error(msg, args)
}
func (this *ModuleBase) Panic(msg string, args ...log.Field) {
this.options.GetLog().Panic(msg, args...)
func (this *ModuleBase) Panic(msg string, args log.Fields) {
this.options.GetLog().Panic(msg, args)
}
func (this *ModuleBase) Fatal(msg string, args ...log.Field) {
this.options.GetLog().Fatal(msg, args...)
func (this *ModuleBase) Fatal(msg string, args log.Fields) {
this.options.GetLog().Fatal(msg, args)
}
func (this *ModuleBase) Debugf(format string, args ...interface{}) {
@ -478,3 +478,25 @@ func (this *ModuleBase) Fatalln(args ...interface{}) {
func (this *ModuleBase) Panicln(args ...interface{}) {
this.options.GetLog().Panicln(args...)
}
func (this *ModuleBase) DebugWithField(msg string, fields log.Fields) {
}
func (this *ModuleBase) InfoWithField(msg string, fields log.Fields) {
}
func (this *ModuleBase) PrintWithField(msg string, fields log.Fields) {
}
func (this *ModuleBase) WarnWithField(msg string, fields log.Fields) {
}
func (this *ModuleBase) ErrorWithField(msg string, fields log.Fields) {
}
func (this *ModuleBase) FatalWithField(msg string, fields log.Fields) {
}
func (this *ModuleBase) PanicWithField(msg string, fields log.Fields) {
}

View File

@ -105,7 +105,7 @@ func (this *Moonfantasy) Trigger(session comm.IUserSession, source *pb.BattleRep
//接收区服worker发起的秘境事件
func (this *Moonfantasy) Rpc_ModuleMoonfantasyTrigger(ctx context.Context, args *pb.RPCGeneralReqA1, reply *pb.EmptyResp) (err error) {
this.Debug("Rpc_ModuleMoonfantasyTrigger", log.Field{Key: "args", Value: args.String()})
this.Debug("Rpc_ModuleMoonfantasyTrigger", log.Fields{"args": args.String()})
if args.Param1 == "" {
err = errors.New("参数异常!")
return

View File

@ -179,6 +179,6 @@ func (this *Pagoda) CheckPoint(uid string) bool {
return true
}
func (this *Pagoda) Rpc_ModuleSeasonPagodaReward(ctx context.Context, args *pb.EmptyReq, reply *pb.EmptyResp) {
this.Debug("Rpc_ModuleSeasonPagodaReward", log.Field{Key: "args", Value: args.String()})
this.Debug("Rpc_ModuleSeasonPagodaReward", log.Fields{"args": args.String()})
this.modulerank.seasonSettlement()
}

View File

@ -62,7 +62,7 @@ func (this *Pay) OnInstallComp() {
//RPC-----------------------------------------------------------------------------------------------------------------------
func (this *Pay) Rpc_ModulePayDelivery(ctx context.Context, args *pb.PayDeliveryReq, reply *pb.PayDeliveryResp) (err error) {
this.Debug("Rpc_ModulePayDelivery", log.Field{Key: "args", Value: args.String()})
this.Debug("Rpc_ModulePayDelivery", log.Fields{ "args": args.String()})
var (
conf *cfg.GameRechargeData
info *pb.DBUserPay

View File

@ -63,7 +63,7 @@ func (this *apiComp) BattleFinish(session comm.IUserSession, req *pb.RtaskBattle
for _, v := range sideConf.EndTid {
if err, ok := this.moduleRtask.modelRtask.checkCondi(session.GetUserId(), v); !ok {
if err != nil {
this.moduleRtask.Error(err.Error())
this.moduleRtask.Errorln(err.Error())
}
this.moduleRtask.Debugf("条件未达成 condiID:%v rtaskId:%v subRtaskId:%v chooseID:%v", v, req.RtaskId, req.RtaskSubId, req.ChooseId)
break

View File

@ -240,7 +240,7 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
return
}
this.Debug("任务事件触发", log.Field{"uid", uid}, log.Field{"taskType", rtaskType}, log.Field{"params", params})
this.Debug("任务事件触发", log.Fields{"uid": uid, "taskType": rtaskType, "params": params})
var (
err error
condiId int32
@ -250,7 +250,7 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
for _, codi := range this.configure.getRtaskCondis(int32(rtaskType)) {
v, ok := this.handleMap[codi.Id]
if !ok {
this.Warn("未注册事件处理器", log.Field{"uid", uid}, log.Field{"condiId", codi.Id})
this.Warn("未注册事件处理器", log.Fields{"uid": uid, "condiId": codi.Id})
code = pb.ErrorCode_RtaskCondiNoFound
return
}
@ -260,7 +260,7 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
}
if condiId, err = v.find(v.cfg, params...); condiId == 0 {
if err != nil {
this.Warn(errors.WithMessage(err, uid).Error())
this.Warnln(errors.WithMessage(err, uid).Error())
}
} else {
condis = append(condis, v)
@ -413,7 +413,7 @@ func (this *ModuleRtask) RemoteCheckCondi(uid string, condiId int32, rsp *pb.DBR
//接收区服worker发起的秘境事件
func (this *ModuleRtask) Rpc_ModuleRtaskSendTask(ctx context.Context, args *pb.RPCRTaskReq, reply *pb.EmptyResp) (err error) {
this.Debug("Rpc_ModuleRtaskSendTask", log.Field{Key: "args", Value: args.String()})
this.Debug("Rpc_ModuleRtaskSendTask", log.Fields{ "args": args.String()})
if args.Uid == "" {
err = errors.New("参数异常!")
return

View File

@ -139,7 +139,7 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq)
var _items []*cfg.GameShopitemData
for _, v := range shopconf.Shopitem {
if _items, err = this.module.configure.GetShopItemsConfigureByGroups(v, udata); err != nil || len(_items) == 0 {
this.module.Error("no founf shopgroup", log.Field{Key: "gid", Value: v})
this.module.Error("no founf shopgroup", log.Fields{"gid": v})
code = pb.ErrorCode_SystemError
return
}

View File

@ -122,7 +122,7 @@ func (this *Sociaty) Reddot(uid string, rid ...comm.ReddotType) (reddot map[comm
// 跨服获取公会
func (this *Sociaty) RpcGetSociaty(ctx context.Context, req *pb.RPCGeneralReqA1, reply *pb.DBSociaty) error {
this.Debug("Rpc_ModuleSociaty", log.Field{Key: "req", Value: req})
this.Debug("Rpc_ModuleSociaty", log.Fields{"req": req})
sociaty := this.modelSociaty.getSociaty(req.Param1)
*reply = *sociaty
return nil

View File

@ -297,7 +297,7 @@ func (this *ModelTask) doTaskHandle(event interface{}, next func(event interface
task, ok := this.checkTask(tl.Uid, conf.Key)
if !ok {
this.moduleTask.Debug("任务已完成", log.Field{"uid", tl.Uid}, log.Field{"任务ID", conf.Key})
this.moduleTask.Debug("任务已完成", log.Fields{"uid": tl.Uid, "任务ID": conf.Key})
continue
}
@ -327,11 +327,7 @@ func (this *ModelTask) doTaskHandle(event interface{}, next func(event interface
return
}
this.moduleTask.Debug("更新任务",
log.Field{"uid", tl.Uid},
log.Field{"任务ID", conf.Key},
log.Field{"事件ID", conf.TypeId},
log.Field{"progress", update["progress"]},
log.Field{"status", update["status"]},
log.Fields{"uid": tl.Uid, "任务ID": conf.Key, "事件ID": conf.TypeId, "progress": update["progress"], "status": update["status"]},
)
}
return

View File

@ -67,7 +67,7 @@ func (this *ChatComp) Start() (err error) {
}
cronStr := fmt.Sprintf("0 %d %d ? * %s", v1.TimeM, v1.TimeH, weekStr)
this.module.Debug("注册Chat广播公告消息", log.Field{Key: "cronStr", Value: cronStr}, log.Field{Key: "text", Value: v1.Text})
this.module.Debug("注册Chat广播公告消息", log.Fields{"cronStr": cronStr, "text": v1.Text})
if id, err = cron.AddFunc(cronStr, this.chatNoticen(v1.Text)); err != nil {
this.module.Errorf("cron.AddFunc:%s err:%v", cronStr, err)
continue
@ -89,7 +89,7 @@ func (this *ChatComp) chatNoticen(content string) func() {
Content: content,
}
data, _ := anypb.New(&pb.ChatMessagePush{Chat: msg})
this.module.Debug("广播公告消息", log.Field{Key: "chat", Value: content})
this.module.Debug("广播公告消息", log.Fields{"chat": content})
if err := this.module.service.RpcBroadcast(context.Background(), comm.Service_Gateway, string(comm.Rpc_GatewaySendRadioMsg), pb.UserMessage{
MainType: string(comm.ModuleChat),
SubType: "message",

View File

@ -77,26 +77,26 @@ func (this *Timer) SetName(name string) {
}
//日志接口
func (this *Timer) Debug(msg string, args ...log.Field) {
this.options.GetLog().Debug(msg, args...)
func (this *Timer) Debug(msg string, args log.Fields) {
this.options.GetLog().Debug(msg, args)
}
func (this *Timer) Info(msg string, args ...log.Field) {
this.options.GetLog().Info(msg, args...)
func (this *Timer) Info(msg string, args log.Fields) {
this.options.GetLog().Info(msg, args)
}
func (this *Timer) Print(msg string, args ...log.Field) {
this.options.GetLog().Print(msg, args...)
func (this *Timer) Print(msg string, args log.Fields) {
this.options.GetLog().Print(msg, args)
}
func (this *Timer) Warn(msg string, args ...log.Field) {
this.options.GetLog().Warn(msg, args...)
func (this *Timer) Warn(msg string, args log.Fields) {
this.options.GetLog().Warn(msg, args)
}
func (this *Timer) Error(msg string, args ...log.Field) {
this.options.GetLog().Error(msg, args...)
func (this *Timer) Error(msg string, args log.Fields) {
this.options.GetLog().Error(msg, args)
}
func (this *Timer) Panic(msg string, args ...log.Field) {
this.options.GetLog().Panic(msg, args...)
func (this *Timer) Panic(msg string, args log.Fields) {
this.options.GetLog().Panic(msg, args)
}
func (this *Timer) Fatal(msg string, args ...log.Field) {
this.options.GetLog().Fatal(msg, args...)
func (this *Timer) Fatal(msg string, args log.Fields) {
this.options.GetLog().Fatal(msg, args)
}
func (this *Timer) Debugf(format string, args ...interface{}) {

View File

@ -58,26 +58,26 @@ func (this *Web) OnInstallComp() {
//日志
//日志接口
func (this *Web) Debug(msg string, args ...log.Field) {
this.options.GetLog().Debug(msg, args...)
func (this *Web) Debug(msg string, args log.Fields) {
this.options.GetLog().Debug(msg, args)
}
func (this *Web) Info(msg string, args ...log.Field) {
this.options.GetLog().Info(msg, args...)
func (this *Web) Info(msg string, args log.Fields) {
this.options.GetLog().Info(msg, args)
}
func (this *Web) Print(msg string, args ...log.Field) {
this.options.GetLog().Print(msg, args...)
func (this *Web) Print(msg string, args log.Fields) {
this.options.GetLog().Print(msg, args)
}
func (this *Web) Warn(msg string, args ...log.Field) {
this.options.GetLog().Warn(msg, args...)
func (this *Web) Warn(msg string, args log.Fields) {
this.options.GetLog().Warn(msg, args)
}
func (this *Web) Error(msg string, args ...log.Field) {
this.options.GetLog().Error(msg, args...)
func (this *Web) Error(msg string, args log.Fields) {
this.options.GetLog().Error(msg, args)
}
func (this *Web) Panic(msg string, args ...log.Field) {
this.options.GetLog().Panic(msg, args...)
func (this *Web) Panic(msg string, args log.Fields) {
this.options.GetLog().Panic(msg, args)
}
func (this *Web) Fatal(msg string, args ...log.Field) {
this.options.GetLog().Fatal(msg, args...)
func (this *Web) Fatal(msg string, args log.Fields) {
this.options.GetLog().Fatal(msg, args)
}
func (this *Web) Debugf(format string, args ...interface{}) {

View File

@ -100,15 +100,15 @@ func Execute() {
//生成配置
func conf() {
if config, err := readergmconf(gmpath); err != nil {
log.Error("读取区服配置失败!", log.Field{Key: "err", Value: err})
log.Error("读取区服配置失败!", log.Fields{"err": err})
} else {
if ss, err := rederServiceSttings(config); err != nil {
log.Error("转换服务配置异常!", log.Field{Key: "err", Value: err})
log.Error("转换服务配置异常!", log.Fields{"err": err})
} else {
for _, v := range ss {
if sid == "" || fmt.Sprintf("%s_%s", v.Tag, sid) == v.Id {
if err = writeServiceConfig(fmt.Sprintf("./conf/%s.yaml", v.Id), v); err != nil {
log.Error("写入配置文件失败!", log.Field{Key: "err", Value: err})
log.Error("写入配置文件失败!", log.Fields{"err": err})
return
}
}
@ -120,7 +120,7 @@ func conf() {
//启动程序
func start() {
if config, err := readergmconf(gmpath); err != nil {
log.Error("读取区服配置失败!", log.Field{Key: "err", Value: err})
log.Error("读取区服配置失败!", log.Fields{"err": err})
} else {
var (
maintes *core.ServiceSttings
@ -128,12 +128,12 @@ func start() {
gateways []*core.ServiceSttings = make([]*core.ServiceSttings, 0)
)
if ss, err := rederServiceSttings(config); err != nil {
log.Error("转换服务配置异常!", log.Field{Key: "err", Value: err})
log.Error("转换服务配置异常!", log.Fields{"err": err})
} else {
for _, v := range ss {
if sid == "" || fmt.Sprintf("%s_%s", v.Tag, sid) == v.Id {
if err = writeServiceConfig(fmt.Sprintf("./conf/%s.yaml", v.Id), v); err != nil {
log.Error("写入配置文件失败!", log.Field{Key: "err", Value: err})
log.Error("写入配置文件失败!", log.Fields{"err": err})
return
}
switch v.Type {
@ -157,7 +157,7 @@ func start() {
//优先启动 维护服
if maintes != nil {
if err = startService(maintes); err != nil {
log.Error("启动服务失败!", log.Field{Key: "id", Value: maintes.Id}, log.Field{Key: "err", Value: err})
log.Error("启动服务失败!", log.Fields{"id": maintes.Id, "err": err})
return
}
}
@ -166,7 +166,7 @@ func start() {
// 业务服
for _, v := range workers {
if err = startService(v); err != nil {
log.Error("启动服务失败!", log.Field{Key: "id", Value: v.Id}, log.Field{Key: "err", Value: err})
log.Error("启动服务失败!", log.Fields{"id": v.Id, "err": err})
return
}
}
@ -174,7 +174,7 @@ func start() {
// 网关服
for _, v := range gateways {
if err = startService(v); err != nil {
log.Error("启动服务失败!", log.Field{Key: "id", Value: v.Id}, log.Field{Key: "err", Value: err})
log.Error("启动服务失败!", log.Fields{"id": v.Id, "err": err})
return
}
}
@ -184,11 +184,11 @@ func start() {
//关闭程序
func stop() {
if config, err := readergmconf(gmpath); err != nil {
log.Error("读取区服配置失败!", log.Field{Key: "err", Value: err})
log.Error("读取区服配置失败!", log.Fields{"err": err})
} else {
if ss, err := rederServiceSttings(config); err != nil {
log.Error("转换服务配置异常!", log.Field{Key: "err", Value: err})
log.Error("转换服务配置异常!", log.Fields{"err": err})
} else {
for _, v := range ss {
if sid == "" || fmt.Sprintf("%s_%s", v.Tag, sid) == v.Id {
@ -346,12 +346,12 @@ func startService(sseting *core.ServiceSttings) (err error) {
err = fmt.Errorf("服务类型异常 stype:%s", sseting.Type)
return
}
log.Debug("启动外部命令", log.Field{Key: "cmd", Value: command})
log.Debug("启动外部命令", log.Fields{"cmd": command})
cmd = exec.Command("/bin/bash", "-c", command)
if output, err = cmd.CombinedOutput(); err != nil {
return
}
log.Debug(string(output))
log.Debugln(string(output))
return
}
@ -376,12 +376,12 @@ func stopService(sseting *core.ServiceSttings) (err error) {
err = fmt.Errorf("服务类型异常 stype:%s", sseting.Type)
return
}
log.Debug("启动外部命令", log.Field{Key: "cmd", Value: command})
log.Debug("启动外部命令", log.Fields{"cmd": command})
cmd = exec.Command("/bin/bash", "-c", command)
if output, err = cmd.CombinedOutput(); err != nil {
return
}
log.Debug(string(output))
log.Debugln(string(output))
return
}

View File

@ -156,21 +156,13 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag
}
// log.Errorf("[Handle Api] t:%v m:%s req:%v reply:%v", time.Since(stime), method, msg, reply)
log.Error("[Handle Api]",
log.Field{Key: "t", Value: time.Since(stime).Milliseconds()},
log.Field{Key: "m", Value: method},
log.Field{Key: "uid", Value: args.UserId},
log.Field{Key: "req", Value: msg},
log.Field{Key: "reply", Value: reply.String()},
log.Fields{"t": time.Since(stime).Milliseconds(), "m": method, "uid": args.UserId, "req": msg, "reply": reply.String()},
)
} else {
reply.Reply = session.Polls()
// log.Debugf("[Handle Api] t:%v m:%s uid:%s req:%v reply:%v", time.Since(stime), method, args.UserId, msg, reply)
log.Debug("[Handle Api]",
log.Field{Key: "t", Value: time.Since(stime).Milliseconds()},
log.Field{Key: "m", Value: method},
log.Field{Key: "uid", Value: args.UserId},
log.Field{Key: "req", Value: msg},
log.Field{Key: "reply", Value: reply.String()},
log.Fields{"t": time.Since(stime).Milliseconds(), "m": method, "uid": args.UserId, "req": msg, "reply": reply.String()},
)
}
} else { //未找到消息处理函数

View File

@ -13,7 +13,7 @@ type TestData struct {
}
func (this *TestData) Log() {
sys.Error("妈妈咪呀!")
sys.Errorln("妈妈咪呀!")
}
var sys log.ISys

View File

@ -202,7 +202,7 @@ func (this *Configure) checkConfigure() {
log.Errorln(err)
return
}
log.Debug("UpDate Configure", log.Field{Key: "table", Value: v.Name})
log.Debug("UpDate Configure", log.Fields{ "table": v.Name})
for _, v := range handle.events {
if v != nil {
go func(f func()) {

View File

@ -71,7 +71,7 @@ func (this *DB) readercrossconf(path string) (err error) {
MongodbUrl: cf.LoaclDB.MongodbUrl,
MongodbDatabase: cf.LoaclDB.MongodbDatabase,
}); err != nil {
log.Error("comment db err!", log.Field{Key: "stag", Value: cf.AreaId}, log.Field{Key: "db", Value: cf.LoaclDB}, log.Field{Key: "err", Value: err})
log.Error("comment db err!", log.Fields{"stag": cf.AreaId, "db": cf.LoaclDB, "err": err})
return
}
} else {
@ -84,7 +84,7 @@ func (this *DB) readercrossconf(path string) (err error) {
MongodbUrl: v.MongodbUrl,
MongodbDatabase: v.MongodbDatabase,
}); err != nil {
log.Error("comment db err!", log.Field{Key: "stag", Value: k}, log.Field{Key: "db", Value: v}, log.Field{Key: "err", Value: err})
log.Error("comment db err!", log.Fields{"stag": k, "db": v, "err": err})
return
}
}

View File

@ -28,14 +28,14 @@ func newDBConn(lg log.ILogger, conf DBConfig) (conn *DBConn, err error) {
)
}
if err != nil {
lg.Error(err.Error(), log.Field{Key: "config", Value: conf})
lg.Error(err.Error(), log.Fields{"config": conf})
return
}
if conn.Mgo, err = mgo.NewSys(
mgo.SetMongodbUrl(conf.MongodbUrl),
mgo.SetMongodbDatabase(conf.MongodbDatabase),
); err != nil {
lg.Error(err.Error(), log.Field{Key: "config", Value: conf})
lg.Error(err.Error(), log.Fields{"config": conf})
return
}
go conn.run()

View File

@ -271,7 +271,7 @@ func (this *DBModel) Change(uid string, data map[string]interface{}, opt ...DBOp
func (this *DBModel) ChangeList(uid string, _id string, data map[string]interface{}, opt ...DBOption) (err error) {
//defer log.Debug("DBModel ChangeList", log.Field{Key: "TableName", Value: this.TableName}, log.Field{Key: "uid", Value: uid}, log.Field{Key: "_id", Value: _id}, log.Field{Key: "data", Value: data})
if err = this.Redis.HMSet(this.ukeylist(uid, _id), data); err != nil {
log.Error("DBModel ChangeList", log.Field{Key: "err", Value: err})
log.Error("DBModel ChangeList", log.Fields{"err": err})
return
}

View File

@ -76,3 +76,9 @@ func BenchmarkInt32ToString(b *testing.B) {
func TestMatrxing(t *testing.T) {
utils.MatrixingHour("2022-10-11 00:00:00")
}
func TestCompre(t *testing.T){
a:=[]int32{1,2,4,5}
b:=[]int32{1,2,4}
fmt.Println(utils.ForContainer(a,b))
}