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:
@@ -20,7 +20,6 @@ type ServerHandler struct{}
|
||||
// 实现踢人
|
||||
func (*ServerHandler) Kick(_ context.Context, userid uint32) error {
|
||||
|
||||
cool.Logger.Info(context.TODO(), "服务器收到踢人")
|
||||
useid1, err := share.ShareManager.GetUserOnline(userid)
|
||||
|
||||
if err != nil {
|
||||
@@ -39,7 +38,7 @@ func (*ServerHandler) Kick(_ context.Context, userid uint32) error {
|
||||
|
||||
// 注册logic服务器
|
||||
func (*ServerHandler) RegisterLogic(ctx context.Context, id, port uint16) error {
|
||||
cool.Logger.Debug(context.Background(), "注册logic服务器", id, port)
|
||||
fmt.Println("注册logic服务器", id, port)
|
||||
|
||||
//TODO 待修复滚动更新可能导致的玩家可以同时在旧服务器和新服务器同时在线的bug
|
||||
revClient, ok := jsonrpc.ExtractReverseClient[cool.ClientHandler](ctx)
|
||||
@@ -59,19 +58,6 @@ func (*ServerHandler) RegisterLogic(ctx context.Context, id, port uint16) error
|
||||
|
||||
}
|
||||
|
||||
// func StartServer() {
|
||||
// // create a new server instance
|
||||
// rpcServer := jsonrpc.NewServer(jsonrpc.WithReverseClient[cool.ClientHandler](""))
|
||||
|
||||
// rpcServer.Register("", &ServerHandler{})
|
||||
// cool.Logger.Debug(context.Background(), "jsonrpc server start", rpcport)
|
||||
// // go time.AfterFunc(3000, func() {
|
||||
// // testjsonrpc()
|
||||
// // })
|
||||
|
||||
// err := http.ListenAndServe("0.0.0.0:"+rpcport, rpcServer)
|
||||
// cool.Logger.Debug(context.Background(), "jsonrpc server fail", err)
|
||||
// }
|
||||
func CServer() *jsonrpc.RPCServer {
|
||||
// create a new server instance
|
||||
rpcServer := jsonrpc.NewServer(jsonrpc.WithReverseClient[cool.ClientHandler](""))
|
||||
@@ -79,8 +65,7 @@ func CServer() *jsonrpc.RPCServer {
|
||||
rpcServer.Register("", &ServerHandler{})
|
||||
|
||||
return rpcServer
|
||||
// err := http.ListenAndServe("0.0.0.0:"+rpcport, rpcServer)
|
||||
// // cool.Logger.Debug(context.Background(), "jsonrpc server fail", err)
|
||||
|
||||
}
|
||||
|
||||
var closer jsonrpc.ClientCloser
|
||||
|
||||
@@ -66,7 +66,7 @@ func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action) {
|
||||
v.LF.Close()
|
||||
if v.Player != nil {
|
||||
v.SaveL.Do(func() { //使用保存锁,确保在踢人和掉线的时候只保存一次
|
||||
//cool.Loger.Info(context.TODO(), "准备保存", v.Player.Info.UserID)
|
||||
|
||||
v.Player.Save() //保存玩家数据
|
||||
|
||||
})
|
||||
@@ -88,8 +88,6 @@ func (s *Server) OnTick() (delay time.Duration, action gnet.Action) {
|
||||
func (s *Server) OnBoot(eng gnet.Engine) gnet.Action {
|
||||
s.eng = eng
|
||||
|
||||
// cool.Loger.Infof(context.Background(), " server is listening on %s\n", s.addr)
|
||||
|
||||
return gnet.None
|
||||
}
|
||||
|
||||
@@ -188,7 +186,7 @@ func (s *Server) handleTCP(conn gnet.Conn) (action gnet.Action) {
|
||||
|
||||
if conn.InboundBuffered() > 0 {
|
||||
if err := conn.Wake(nil); err != nil { // wake up the connection manually to avoid missing the leftover data
|
||||
cool.Logger.Errorf(context.Background(), "failed to wake up the connection, %v", err)
|
||||
|
||||
return gnet.Close
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,9 @@ package socket
|
||||
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/cool"
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/base/service"
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
@@ -16,7 +14,6 @@ type Broadcast struct {
|
||||
}
|
||||
|
||||
func (s *Server) Broadcast(t string) int {
|
||||
cool.Logger.Info(context.TODO(), "全服广播", t)
|
||||
|
||||
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
|
||||
|
||||
@@ -32,7 +29,7 @@ func (s *Server) Broadcast(t string) int {
|
||||
const kickTimeout = 5 * time.Second
|
||||
|
||||
func (s *Server) KickPerson(a int) error {
|
||||
cool.Logger.Info(context.TODO(), "检测到踢人请求", a)
|
||||
|
||||
if a == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ func (m *CsMap[K, V]) produce(ctx context.Context, ch chan Tuple[K, V]) {
|
||||
if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值
|
||||
// 1. 打印错误信息
|
||||
|
||||
cool.Logger.Error(context.TODO(), "panic 错误:", err)
|
||||
cool.Logger.Error(context.TODO(), "csmap panic 错误:", err)
|
||||
|
||||
}
|
||||
}()
|
||||
@@ -281,7 +281,7 @@ func (m *CsMap[K, V]) listen(f func(key K, value V) (stop bool), ch chan Tuple[K
|
||||
if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值
|
||||
// 1. 打印错误信息
|
||||
|
||||
cool.Logger.Error(context.TODO(), "panic 错误:", err)
|
||||
cool.Logger.Error(context.TODO(), " csmap panic 错误:", err)
|
||||
|
||||
}
|
||||
}()
|
||||
|
||||
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)
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"blazing/common/utils"
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
@@ -35,7 +34,7 @@ func NewServerService() *ServerService {
|
||||
subm := r[i].GMap()
|
||||
|
||||
if ok {
|
||||
cool.Logger.Info(context.TODO(), "服务器假踢人")
|
||||
|
||||
err := t.KickPerson(0) //实现指定服务器踢人
|
||||
|
||||
if err == nil {
|
||||
|
||||
@@ -3,7 +3,6 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
@@ -27,7 +26,7 @@ func NewDoneService(id uint32) *DoneService {
|
||||
}
|
||||
|
||||
// ID
|
||||
// 击杀-捕捉
|
||||
// 击杀-捕捉
|
||||
func (s *DoneService) UpdatePet(ptye model.PetInfo, res ...uint32) {
|
||||
|
||||
//属性->属性值->ID 击杀-捕捉-炫彩击杀-炫彩捕捉 雄性 雌性
|
||||
@@ -51,7 +50,7 @@ func (s *DoneService) UpdatePet(ptye model.PetInfo, res ...uint32) {
|
||||
func (s *DoneService) update(ptye model.EnumMilestone, args []uint32, results []uint32) {
|
||||
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid)
|
||||
|
||||
return
|
||||
}
|
||||
ar := gconv.String(args)
|
||||
|
||||
@@ -180,7 +180,6 @@ func (s *InfoService) Gensession() string {
|
||||
|
||||
func (s *InfoService) Kick(id uint32) error {
|
||||
|
||||
cool.Logger.Info(context.TODO(), "服务器收到踢人")
|
||||
useid1, err := share.ShareManager.GetUserOnline(id)
|
||||
|
||||
if err != nil {
|
||||
@@ -198,7 +197,6 @@ func (s *InfoService) Kick(id uint32) error {
|
||||
}
|
||||
func (s *InfoService) Save(data model.PlayerInfo) {
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
cool.Logger.Info(context.TODO(), "测试服不保存玩家数据", s.userid)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func (s *ItemService) Get(min, max uint32) []model.Item {
|
||||
}
|
||||
func (s *ItemService) UPDATE(id uint32, count int) {
|
||||
if cool.Config.ServerInfo.IsVip != 0 && count < 0 {
|
||||
cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid)
|
||||
|
||||
return
|
||||
}
|
||||
m := s.TestModel(s.Model)
|
||||
|
||||
@@ -41,7 +41,7 @@ func (s *RoomService) Get(userid uint32) model.BaseHouseEx {
|
||||
func (s *RoomService) Set(id []model.FitmentShowInfo) {
|
||||
//todo待测试
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid)
|
||||
|
||||
return
|
||||
}
|
||||
var ttt model.BaseHouseEx
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"blazing/cool"
|
||||
config "blazing/modules/config/service"
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
)
|
||||
|
||||
type TalkService struct {
|
||||
@@ -54,7 +53,7 @@ func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) {
|
||||
}
|
||||
func (s *TalkService) Update(flag int) {
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid)
|
||||
|
||||
return
|
||||
}
|
||||
m := s.PModel(s.Model).Where("talk_id", flag)
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
package demo
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
_ "blazing/modules/space/controller"
|
||||
_ "blazing/modules/space/middleware"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func init() {
|
||||
var (
|
||||
ctx = gctx.GetInitCtx()
|
||||
)
|
||||
cool.Logger.Debug(ctx, "module space init start ...")
|
||||
cool.Logger.Debug(ctx, "module space init finished ...")
|
||||
// var (
|
||||
// ctx = gctx.GetInitCtx()
|
||||
// )
|
||||
fmt.Println("module space init start ...")
|
||||
fmt.Println("module space init finished ...")
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package demo
|
||||
|
||||
import (
|
||||
_ "blazing/modules/task/packed"
|
||||
"fmt"
|
||||
|
||||
"blazing/cool"
|
||||
|
||||
@@ -18,7 +19,7 @@ func init() {
|
||||
taskInfo = model.NewTaskInfo()
|
||||
ctx = gctx.GetInitCtx()
|
||||
)
|
||||
cool.Logger.Debug(ctx, "module task init start ...")
|
||||
fmt.Println("module task init start ...")
|
||||
cool.FillInitData(ctx, "task", taskInfo, nil)
|
||||
|
||||
result, err := cool.DBM(taskInfo).Where("status", 1).All()
|
||||
@@ -29,6 +30,6 @@ func init() {
|
||||
id := v["id"].String()
|
||||
cool.RunFunc(ctx, "TaskAddTask("+id+")")
|
||||
}
|
||||
cool.Logger.Debug(ctx, "module task init finished ...")
|
||||
fmt.Println("module task init finished ...")
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user