refactor(logging): 统一使用自定义Loger替代g.Log()日志记录
This commit is contained in:
@@ -183,7 +183,7 @@ func getModelInfo(ctx g.Ctx, prefix string, model IModel) (columns []*ColumnInfo
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// g.Log().Info(ctx, "fields", fields)
|
||||
// Loger.Info(ctx, "fields", fields)
|
||||
sortedFields := garray.NewArraySize(len(fields), len(fields))
|
||||
for _, field := range fields {
|
||||
sortedFields.Set(field.Index, field)
|
||||
|
||||
@@ -28,7 +28,7 @@ func init() {
|
||||
ctx = gctx.GetInitCtx()
|
||||
redisConfig = &gredis.Config{}
|
||||
)
|
||||
g.Log().Debug(ctx, "module cool init start ...")
|
||||
Loger.Debug(ctx, "module cool init start ...")
|
||||
buildData := gbuild.Data()
|
||||
if _, ok := buildData["mode"]; ok {
|
||||
RunMode = buildData["mode"].(string)
|
||||
@@ -38,7 +38,7 @@ func init() {
|
||||
}
|
||||
redisVar, err := g.Cfg().Get(ctx, "redis.cool")
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "初始化缓存失败,请检查配置文件")
|
||||
Loger.Error(ctx, "初始化缓存失败,请检查配置文件")
|
||||
panic(err)
|
||||
}
|
||||
if !redisVar.IsEmpty() {
|
||||
@@ -50,10 +50,10 @@ func init() {
|
||||
CacheManager.SetAdapter(gcache.NewAdapterRedis(redis))
|
||||
IsRedisMode = true
|
||||
}
|
||||
//g.Log().Debug(ctx, "当前运行模式", RunMode)
|
||||
g.Log().Debug(ctx, "当前实例ID:", ProcessFlag)
|
||||
g.Log().Debug(ctx, "是否缓存模式:", IsRedisMode)
|
||||
g.Log().Debug(ctx, "module cool init finished ...")
|
||||
//Logerebug(ctx, "当前运行模式", RunMode)
|
||||
Loger.Debug(ctx, "当前实例ID:", ProcessFlag)
|
||||
Loger.Debug(ctx, "是否缓存模式:", IsRedisMode)
|
||||
Loger.Debug(ctx, "module cool init finished ...")
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ func GetAdmin(ctx context.Context) *Admin {
|
||||
admin := &Admin{}
|
||||
err := gjson.New(r.GetCtxVar("admin").String()).Scan(admin)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, err)
|
||||
Loger.Error(ctx, err)
|
||||
}
|
||||
return admin
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func RunFunc(ctx g.Ctx, funcstring string) (err error) {
|
||||
if !FuncMap[funcName].IsAllWorker() {
|
||||
// 检查当前是否为主进程, 如果不是主进程, 则不执行
|
||||
if ProcessFlag != CacheManager.MustGetOrSet(ctx, "cool:masterflag", ProcessFlag, 60*time.Second).String() {
|
||||
g.Log().Debug(ctx, "当前进程不是主进程, 不执行单例函数", funcName)
|
||||
Loger.Debug(ctx, "当前进程不是主进程, 不执行单例函数", funcName)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func ListenFunc(ctx g.Ctx) {
|
||||
for {
|
||||
data, err := conn.Receive(ctx)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, err)
|
||||
Loger.Error(ctx, err)
|
||||
time.Sleep(10 * time.Second)
|
||||
continue
|
||||
}
|
||||
@@ -89,10 +89,10 @@ func ListenFunc(ctx g.Ctx) {
|
||||
continue
|
||||
}
|
||||
if dataMap["Channel"] == "cool:func" {
|
||||
g.Log().Debug(ctx, "执行函数", dataMap["Payload"])
|
||||
Loger.Debug(ctx, "执行函数", dataMap["Payload"])
|
||||
err := RunFunc(ctx, dataMap["Payload"])
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "执行函数失败", err)
|
||||
Loger.Error(ctx, "执行函数失败", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,19 @@ import (
|
||||
"github.com/yitter/idgenerator-go/idgen"
|
||||
)
|
||||
|
||||
var ctx = context.TODO()
|
||||
|
||||
var (
|
||||
Mainplayer = &utils.SyncMap[uint32, *entity.Player]{} //玩家数据
|
||||
CmdCache = &utils.SyncMap[uint32, reflect.Value]{} //命令缓存
|
||||
|
||||
Loger = glog.New()
|
||||
)
|
||||
|
||||
func init() {
|
||||
// 创建 IdGeneratorOptions 对象,可在构造函数中输入 WorkerId:
|
||||
Loger.SetFlags(glog.F_TIME_STD | glog.F_FILE_LONG) //设置flag
|
||||
Loger.Print(ctx, "初始化日志")
|
||||
tt := gconv.Uint16(1)
|
||||
var options = idgen.NewIdGeneratorOptions(tt)
|
||||
// options.WorkerIdBitLength = 10 // 默认值6,限定 WorkerId 最大值为2^6-1,即默认最多支持64个节点。
|
||||
|
||||
@@ -65,30 +65,30 @@ func FillInitData(ctx g.Ctx, moduleName string, model IModel, ismod *bool) (bool
|
||||
mInit := g.DB("default").Model("base_sys_init")
|
||||
n, err := mInit.Clone().Where("group", model.GroupName()).Where("table", model.TableName()).Count()
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "读取表 base_sys_init 失败 ", err.Error())
|
||||
Loger.Error(ctx, "读取表 base_sys_init 失败 ", err.Error())
|
||||
return false, err
|
||||
}
|
||||
if n > 0 {
|
||||
g.Log().Debug(ctx, "分组", model.GroupName(), "中的表", model.TableName(), "已经初始化过,跳过本次初始化.")
|
||||
Loger.Debug(ctx, "分组", model.GroupName(), "中的表", model.TableName(), "已经初始化过,跳过本次初始化.")
|
||||
return false, err
|
||||
}
|
||||
m := g.DB(model.GroupName()).Model(model.TableName())
|
||||
jsonData, _ := gjson.LoadContent(gres.GetContent("modules/" + moduleName + "/resource/initjson/" + model.TableName() + ".json"))
|
||||
if jsonData.Var().Clone().IsEmpty() {
|
||||
g.Log().Debug(ctx, "分组", model.GroupName(), "中的表", model.TableName(), "无可用的初始化数据,跳过本次初始化.")
|
||||
Loger.Debug(ctx, "分组", model.GroupName(), "中的表", model.TableName(), "无可用的初始化数据,跳过本次初始化.")
|
||||
return false, err
|
||||
}
|
||||
_, err = m.Data(jsonData).Insert()
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, err.Error())
|
||||
Loger.Error(ctx, err.Error())
|
||||
return false, err
|
||||
}
|
||||
_, err = mInit.Insert(g.Map{"group": model.GroupName(), "table": model.TableName()})
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, err.Error())
|
||||
Loger.Error(ctx, err.Error())
|
||||
return false, err
|
||||
}
|
||||
g.Log().Info(ctx, "分组", model.GroupName(), "中的表", model.TableName(), "初始化完成.")
|
||||
Loger.Info(ctx, "分组", model.GroupName(), "中的表", model.TableName(), "初始化完成.")
|
||||
if ismod != nil {
|
||||
*ismod = true
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
package cool
|
||||
@@ -37,7 +37,7 @@ func MiddlewareHandlerResponse(r *ghttp.Request) {
|
||||
code = gerror.Code(err).Code()
|
||||
)
|
||||
|
||||
// g.Log().Debug(ctx, code, msg, res)
|
||||
// Loger.Debug(ctx, code, msg, res)
|
||||
msg = "success"
|
||||
|
||||
if err != nil {
|
||||
@@ -67,7 +67,7 @@ func MiddlewareHandlerResponse(r *ghttp.Request) {
|
||||
code = 1003
|
||||
default:
|
||||
}
|
||||
// g.Log().Debug(ctx, code, msg, res)
|
||||
// Loger.Debug(ctx, code, msg, res)
|
||||
// 如果是正常返回,直接返回res
|
||||
if code == 1000 && r.Response.Status == 200 {
|
||||
r.Response.WriteJsonExit(res)
|
||||
|
||||
@@ -242,7 +242,7 @@ func (s *Service) ServiceList(ctx context.Context, req *ListReq) (data interface
|
||||
|
||||
result, err := m.All()
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "ServiceList error:", err)
|
||||
Loger.Error(ctx, "ServiceList error:", err)
|
||||
}
|
||||
if result == nil {
|
||||
data = garray.New()
|
||||
@@ -407,7 +407,7 @@ func (s *Service) ServicePage(ctx context.Context, req *PageReq) (data interface
|
||||
|
||||
// ModifyBefore 新增|删除|修改前的操作
|
||||
func (s *Service) ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error) {
|
||||
// g.Log().Debugf(ctx, "ModifyBefore: %s", method)
|
||||
// Loger.Debugf(ctx, "ModifyBefore: %s", method)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gobwas/ws"
|
||||
"github.com/gobwas/ws/wsutil"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/panjf2000/gnet/v2"
|
||||
"github.com/panjf2000/gnet/v2/pkg/logging"
|
||||
)
|
||||
@@ -29,7 +26,7 @@ func (c *Conn) SendPack(bytes []byte) error {
|
||||
|
||||
_, err := c.MainConn.Write(bytes)
|
||||
if err != nil {
|
||||
g.Log().Error(context.Background(), err)
|
||||
logging.Error( err)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ package rpc
|
||||
|
||||
import (
|
||||
"blazing/common/data/share"
|
||||
"blazing/cool"
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/filecoin-project/go-jsonrpc"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
const rpcaddr = "127.0.0.1:40000"
|
||||
@@ -71,13 +71,13 @@ func StartServer() {
|
||||
rpcServer := jsonrpc.NewServer(jsonrpc.WithReverseClient[ClientHandler](""))
|
||||
|
||||
rpcServer.Register("", &ServerHandler{})
|
||||
g.Log().Debug(context.Background(), "jsonrpc server start")
|
||||
cool.Loger.Debug(context.Background(), "jsonrpc server start")
|
||||
// go time.AfterFunc(3000, func() {
|
||||
// testjsonrpc()
|
||||
// })
|
||||
|
||||
err := http.ListenAndServe(rpcaddr, rpcServer)
|
||||
g.Log().Debug(context.Background(), "jsonrpc server fail", err)
|
||||
cool.Loger.Debug(context.Background(), "jsonrpc server fail", err)
|
||||
}
|
||||
|
||||
var closer jsonrpc.ClientCloser
|
||||
|
||||
Reference in New Issue
Block a user