refactor(logging): 统一使用自定义Loger替代g.Log()日志记录

This commit is contained in:
1
2025-07-26 03:48:06 +00:00
parent dcc5ef047c
commit 5d2b48ccc0
26 changed files with 72 additions and 73 deletions

View File

@@ -10,7 +10,7 @@ type TaskTest struct {
}
func (t *TaskTest) Func(ctx g.Ctx, param string) error {
g.Log().Info(ctx, "TaskTest Run ~~~~~~~~~~~~~~~~", param)
cool.Loger.Info(ctx, "TaskTest Run ~~~~~~~~~~~~~~~~", param)
return nil
}
func (t *TaskTest) IsSingleton() bool {

View File

@@ -24,12 +24,12 @@ func EnableTask(ctx g.Ctx, cronId string, funcstring string, cron string, startD
_, err = gcron.AddSingleton(ctx, cron, func(ctx g.Ctx) {
nowDate := gtime.Now().Format("Y-m-d H:i:s")
if nowDate < startDate {
g.Log().Debug(ctx, "当前时间小于启用时间, 不执行单例函数", funcName)
cool.Loger.Debug(ctx, "当前时间小于启用时间, 不执行单例函数", funcName)
return
}
err := cool.RunFunc(ctx, funcstring)
if err != nil {
g.Log().Error(ctx, err)
cool.Loger.Error(ctx, err)
taskInfoService.Record(ctx, cronId, 0, err.Error())
} else {
taskInfoService.Record(ctx, cronId, 1, "任务执行成功")
@@ -40,12 +40,12 @@ func EnableTask(ctx g.Ctx, cronId string, funcstring string, cron string, startD
_, err = gcron.Add(ctx, cron, func(ctx g.Ctx) {
nowDate := gtime.Now().Format("Y-m-d H:i:s")
if nowDate < startDate {
g.Log().Debug(ctx, "当前时间小于启用时间, 不执行函数", funcName)
cool.Loger.Debug(ctx, "当前时间小于启用时间, 不执行函数", funcName)
return
}
err := cool.RunFunc(ctx, funcstring)
if err != nil {
g.Log().Error(ctx, err)
cool.Loger.Error(ctx, err)
taskInfoService.Record(ctx, cronId, 0, gstr.AddSlashes(err.Error()))
} else {
taskInfoService.Record(ctx, cronId, 1, gstr.AddSlashes("任务执行成功"))

View File

@@ -32,7 +32,7 @@ func NewTaskInfoService() *TaskInfoService {
}
func (s *TaskInfoService) ModifyAfter(ctx g.Ctx, method string, param g.MapStrAny) (err error) {
g.Log().Info(ctx, "TaskInfoService.ModifyAfter", method, param)
cool.Loger.Info(ctx, "TaskInfoService.ModifyAfter", method, param)
if method == "Add" {
if gconv.Int(param["status"]) == 1 {
id, err := cool.DBM(s.Model).Where("name", param["name"]).Value("id")
@@ -146,7 +146,7 @@ func (s *TaskInfoService) Log(ctx g.Ctx, param g.MapStrStr) (data interface{}, e
},
}, nil
}
// g.Log().Info(ctx, "TaskInfoService.Log", result)
// Loger.Info(ctx, "TaskInfoService.Log", result)
data = g.Map{
"list": result,
"pagination": g.Map{
@@ -169,7 +169,7 @@ func (s *TaskInfoService) SetNextRunTime(ctx g.Ctx, cronId string, cron string)
return err
}
} else {
g.Log().Debug(ctx, "获取下次执行时间失败", e)
cool.Loger.Debug(ctx, "获取下次执行时间失败", e)
}
return nil

View File

@@ -10,7 +10,6 @@ import (
_ "blazing/modules/task/middleware"
"blazing/modules/task/model"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
@@ -19,7 +18,7 @@ func init() {
taskInfo = model.NewTaskInfo()
ctx = gctx.GetInitCtx()
)
g.Log().Debug(ctx, "module task init start ...")
cool.Loger.Debug(ctx, "module task init start ...")
cool.FillInitData(ctx, "task", taskInfo, nil)
result, err := cool.DBM(taskInfo).Where("status", 1).All()
@@ -30,6 +29,6 @@ func init() {
id := v["id"].String()
cool.RunFunc(ctx, "TaskAddTask("+id+")")
}
g.Log().Debug(ctx, "module task init finished ...")
cool.Loger.Debug(ctx, "module task init finished ...")
}