refactor: 移除冗余日志输出并优化日志处理
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
xinian
2026-02-02 18:32:41 +08:00
parent acc9bcf6ff
commit cdb7cec4ad
17 changed files with 59 additions and 100 deletions

View File

@@ -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

View File

@@ -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
}
}

View File

@@ -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
}

View File

@@ -248,7 +248,7 @@ func (m *CsMap[K, V]) produce(ctx context.Context, ch chan Tuple[K, V]) {
if err := recover(); err != nil { // 恢复 panicerr 为 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 { // 恢复 panicerr 为 panic 错误值
// 1. 打印错误信息
cool.Logger.Error(context.TODO(), "panic 错误:", err)
cool.Logger.Error(context.TODO(), " csmap panic 错误:", err)
}
}()