```feat(log): 优化日志配置,添加异步日志标志并替换socket服务中的日志输出方式

This commit is contained in:
1
2025-12-11 20:27:10 +00:00
parent 32c61f37bd
commit 5ecfd0396c
2 changed files with 4 additions and 2 deletions

View File

@@ -37,7 +37,7 @@ var DefaultGenerator = utils.NewGen(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC),
func init() {
// 创建 IdGeneratorOptions 对象,可在构造函数中输入 WorkerId
Loger.SetFlags(glog.F_TIME_STD | glog.F_FILE_LONG) //设置flag
Loger.SetFlags(glog.F_TIME_STD | glog.F_FILE_LONG | glog.F_ASYNC) //设置flag
Loger.Print(ctx, "初始化日志")
// for i := 0; i < 600; i++ {
// glog.Debug(context.Background(), i, "初始化雪花算法", DefaultGenerator.Get())

View File

@@ -11,6 +11,8 @@ import (
"blazing/cool"
"blazing/logic/service/player"
"github.com/gogf/gf/v2/os/glog"
"github.com/gogf/gf/v2/os/gtime"
"github.com/panjf2000/gnet/v2"
)
@@ -75,7 +77,7 @@ func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action) {
return
}
func (s *Server) OnTick() (delay time.Duration, action gnet.Action) {
cool.Loger.Infof(context.Background(), "[connected-count=%v]", atomic.LoadInt64(&s.connected))
glog.Infof(context.Background(), gtime.Now().ISO8601(), "[connected-count=%v]", atomic.LoadInt64(&s.connected))
if s.quit && atomic.LoadInt64(&s.connected) == 0 {
//执行正常退出逻辑
os.Exit(0)