refactor: 移除冗余日志输出并优化日志处理
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
30
logic/service/common/log.go
Normal file
30
logic/service/common/log.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/base/service"
|
||||
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
)
|
||||
|
||||
type MyWriter struct {
|
||||
logger *glog.Logger
|
||||
user uint32
|
||||
}
|
||||
|
||||
func (w *MyWriter) Write(p []byte) (n int, err error) {
|
||||
var (
|
||||
s = string(p)
|
||||
//ctx = context.Background()
|
||||
)
|
||||
|
||||
service.NewBaseSysLogService().RecordFight(w.user, s)
|
||||
return w.logger.Write(p)
|
||||
}
|
||||
func init() {
|
||||
cool.Logger.SetWriter(&MyWriter{
|
||||
logger: glog.New(),
|
||||
})
|
||||
cool.Logger.SetAsync(true)
|
||||
|
||||
}
|
||||
@@ -1,13 +1,10 @@
|
||||
package fight
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight/action"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
"context"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
)
|
||||
@@ -28,7 +25,7 @@ func (*FightC) Compare(a, b action.BattleActionI) (action.BattleActionI, action.
|
||||
// 玩家逃跑/无响应/掉线
|
||||
func (f *FightC) Over(c common.PlayerI, res info.EnumBattleOverReason) {
|
||||
if f.closefight {
|
||||
cool.Logger.Debug(context.Background(), " 战斗chan已关闭")
|
||||
|
||||
return
|
||||
}
|
||||
if f.Info.Status != info.BattleMode.FIGHT_WITH_NPC && res == info.BattleOverReason.PlayerEscape {
|
||||
@@ -57,7 +54,7 @@ func (f *FightC) Over(c common.PlayerI, res info.EnumBattleOverReason) {
|
||||
func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
|
||||
|
||||
if f.closefight {
|
||||
cool.Logger.Debug(context.Background(), " 战斗chan已关闭")
|
||||
|
||||
return
|
||||
}
|
||||
//todo 待实现无法切精灵的情况
|
||||
@@ -72,7 +69,7 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
|
||||
// 玩家使用技能
|
||||
func (f *FightC) UseSkill(c common.PlayerI, id uint32) {
|
||||
if f.closefight {
|
||||
cool.Logger.Debug(context.Background(), " 战斗chan已关闭")
|
||||
|
||||
return
|
||||
}
|
||||
ret := &action.SelectSkillAction{
|
||||
@@ -96,7 +93,7 @@ func (f *FightC) UseSkill(c common.PlayerI, id uint32) {
|
||||
// 玩家使用技能
|
||||
func (f *FightC) Capture(c common.PlayerI, id uint32) {
|
||||
if f.closefight {
|
||||
cool.Logger.Debug(context.Background(), " 战斗chan已关闭")
|
||||
|
||||
return
|
||||
}
|
||||
f.actionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: id}
|
||||
@@ -104,7 +101,7 @@ func (f *FightC) Capture(c common.PlayerI, id uint32) {
|
||||
|
||||
func (f *FightC) UseItem(c common.PlayerI, cacthid, itemid uint32) {
|
||||
if f.closefight {
|
||||
cool.Logger.Debug(context.Background(), " 战斗chan已关闭")
|
||||
|
||||
return
|
||||
}
|
||||
f.actionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: itemid, CacthTime: cacthid}
|
||||
@@ -169,15 +166,3 @@ func (f *FightC) startBattle(startInfo info.FightStartOutboundInfo) {
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// var Fightpool *ants.PoolWithFuncGeneric[*FightC]
|
||||
|
||||
// func init() {
|
||||
// Fightpool, _ = ants.NewPoolWithFuncGeneric(-1, func(f *FightC) {
|
||||
// f.battleLoop()
|
||||
// }, ants.WithPanicHandler(func(a any) {
|
||||
// cool.Logger.Debug(context.Background(), "战斗池发生panic", "error", a)
|
||||
// }),
|
||||
// )
|
||||
// //defer p.Release()
|
||||
// }
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/common/utils"
|
||||
"blazing/cool"
|
||||
"blazing/modules/base/service"
|
||||
"context"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
@@ -18,38 +17,15 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/alpacahq/alpacadecimal"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var fightpanlog = glog.New()
|
||||
|
||||
type MyWriter struct {
|
||||
logger *glog.Logger
|
||||
user uint32
|
||||
}
|
||||
|
||||
func (w *MyWriter) Write(p []byte) (n int, err error) {
|
||||
var (
|
||||
s = string(p)
|
||||
//ctx = context.Background()
|
||||
)
|
||||
|
||||
service.NewBaseSysLogService().RecordFight(w.user, s)
|
||||
return w.logger.Write(p)
|
||||
}
|
||||
func init() {
|
||||
fightpanlog.SetWriter(&MyWriter{
|
||||
logger: glog.New(),
|
||||
})
|
||||
|
||||
}
|
||||
func (f *FightC) battleLoop() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值
|
||||
// 1. 打印错误信息
|
||||
var ctx = context.Background()
|
||||
fightpanlog.Errorf(ctx, "%+v", err)
|
||||
cool.Logger.Error(ctx, f.ownerID, err)
|
||||
f.Broadcast(func(ff *input.Input) {
|
||||
if p, ok := ff.Player.(*player.Player); ok {
|
||||
head := common.NewTomeeHeader(1001, p.Info.UserID)
|
||||
@@ -306,10 +282,6 @@ func (f *FightC) resolveRound(p1Action, p2Action action.BattleActionI) {
|
||||
|
||||
// handleActiveSwitchAction 处理主动切换精灵动作
|
||||
func (f *FightC) handleActiveSwitchAction(switchAction *action.ActiveSwitchAction, otherAction action.BattleActionI) {
|
||||
input := f.GetInputByAction(switchAction, false)
|
||||
if input.CurrentPet.Info.Hp <= 0 {
|
||||
input.CurrentPet.Info.Hp = 1
|
||||
}
|
||||
|
||||
if skillAction, ok := otherAction.(*action.SelectSkillAction); ok {
|
||||
if skillAction.SkillEntity != nil && skillAction.CD != nil {
|
||||
|
||||
@@ -6,7 +6,5 @@ import (
|
||||
|
||||
func (p *Player) SendPackCmd(cmd uint32, b any) {
|
||||
|
||||
// cool.Loger.Debug(context.Background(), "发送数据", p.Info.UserID, cmd)
|
||||
|
||||
p.SendPack(common.NewTomeeHeader(cmd, p.Info.UserID).Pack(b))
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ func (p *Player) ItemAdd(ItemId, ItemCnt uint32) (result bool) {
|
||||
default:
|
||||
itemmax := dictrvice.NewDictInfoService().GetMax(ItemId)
|
||||
if itemmax == 0 {
|
||||
cool.Logger.Error(context.TODO(), "物品不存在", ItemId)
|
||||
cool.Logger.Error(context.TODO(), "物品不存在", p.Info.UserID, ItemId)
|
||||
|
||||
t1 := common.NewTomeeHeader(2601, p.Info.UserID)
|
||||
t1.Result = uint32(errorcode.ErrorCodes.ErrSystemError200007)
|
||||
|
||||
Reference in New Issue
Block a user