优化日志堆栈输出和任务系统代码

This commit is contained in:
liwei1dao 2023-05-23 16:03:34 +08:00
parent 6e2f8e997c
commit a4a40f0e7d
6 changed files with 44 additions and 51 deletions

View File

@ -82,32 +82,42 @@ 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) Info(msg string, args ...Field) {
this.Log(InfoLevel, msg, args...)
}
func (this *Logger) Print(msg string, args ...Field) {
this.Log(InfoLevel, msg, args...)
}
func (this *Logger) Warn(msg string, args ...Field) {
this.Log(WarnLevel, msg, args...)
}
func (this *Logger) Error(msg string, args ...Field) {
this.Log(ErrorLevel, msg, args...)
}
func (this *Logger) Panic(msg string, args ...Field) {
this.Log(PanicLevel, msg, args...)
}
func (this *Logger) Fatal(msg string, args ...Field) {
this.Log(FatalLevel, msg, args...)
os.Exit(1)
}
func (this *Logger) Log(level Loglevel, msg string, args ...Field) {
if this.level.Enabled(level) {
this.logWithFields(level, msg, args...)
if this.level.Enabled(DebugLevel) {
this.logWithFields(DebugLevel, msg, args...)
}
}
func (this *Logger) Info(msg string, args ...Field) {
if this.level.Enabled(InfoLevel) {
this.logWithFields(InfoLevel, msg, args...)
}
}
func (this *Logger) Print(msg string, args ...Field) {
if this.level.Enabled(InfoLevel) {
this.logWithFields(InfoLevel, msg, args...)
}
}
func (this *Logger) Warn(msg string, args ...Field) {
if this.level.Enabled(WarnLevel) {
this.logWithFields(WarnLevel, msg, args...)
}
}
func (this *Logger) Error(msg string, args ...Field) {
if this.level.Enabled(ErrorLevel) {
this.logWithFields(ErrorLevel, msg, args...)
}
}
func (this *Logger) Panic(msg string, args ...Field) {
if this.level.Enabled(PanicLevel) {
this.logWithFields(PanicLevel, msg, args...)
}
}
func (this *Logger) Fatal(msg string, args ...Field) {
if this.level.Enabled(FatalLevel) {
this.logWithFields(ErrorLevel, msg, args...)
}
os.Exit(1)
}
func (this *Logger) Debugf(format string, args ...interface{}) {
this.Logf(DebugLevel, format, args...)
}

View File

@ -167,7 +167,7 @@ func (this *apiComp) Equip(session comm.IUserSession, req *pb.EquipmentEquipReq)
code = pb.ErrorCode_SystemError
return
}
tasks = append(tasks, comm.GettaskParam(comm.Rtype5, 1, equipNum, utils.ToInt32(hero.HeroID)))
tasks = append(tasks, comm.GettaskParam(comm.Rtype5, equipNum, utils.ToInt32(hero.HeroID)))
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype5, utils.ToInt32(hero.HeroID), equipNum)
for k, v := range equipStr {
tasks = append(tasks, comm.GettaskParam(comm.Rtype41, 1, utils.ToInt32(hero.HeroID), v, k))

View File

@ -51,6 +51,9 @@ func (this *Items) Start() (err error) {
}
this.privilege = module.(comm.IPrivilege)
event.RegisterGO(comm.EventUserOffline, this.EventUserOffline)
this.Error("日志测试1")
this.Errorf("日志测试2")
this.Errorln("日志测试3")
return
}

View File

@ -609,28 +609,6 @@ func (this *ModuleBase) Panicln(args ...interface{}) {
this.options.GetLog().Panicln(args...)
}
func (this *ModuleBase) DebugWithField(msg string, fields ...log.Field) {
}
func (this *ModuleBase) InfoWithField(msg string, fields ...log.Field) {
}
func (this *ModuleBase) PrintWithField(msg string, fields ...log.Field) {
}
func (this *ModuleBase) WarnWithField(msg string, fields ...log.Field) {
}
func (this *ModuleBase) ErrorWithField(msg string, fields ...log.Field) {
}
func (this *ModuleBase) FatalWithField(msg string, fields ...log.Field) {
}
func (this *ModuleBase) PanicWithField(msg string, fields ...log.Field) {
}
// 发放资源
func (this *ModuleBase) DispenseAtno(session comm.IUserSession, res []*cfg.Gameatn, bPush bool) (code pb.ErrorCode, atno []*pb.UserAtno) {
var (

View File

@ -278,9 +278,11 @@ func (this *ModelTask) initTask(uid string, taskTag comm.TaskTag) error {
}
}
if err := this.Change(uid, update); err != nil {
this.moduleTask.Errorf("initTask err %v", err)
return err
if len(update) > 0 {
if err := this.Change(uid, update); err != nil {
this.moduleTask.Errorf("initTask err %v", err)
return err
}
}
return nil
}

View File

@ -65,7 +65,7 @@ func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err
)
return
}
this.module.Error("Get", log.Field{Key: "uid", Value: uid})
// this.module.Error("Get", log.Field{Key: "uid", Value: uid})
return result, err
}
}