refactor(logging): 统一使用自定义Loger替代g.Log()日志记录
This commit is contained in:
@@ -31,7 +31,7 @@ func init() {
|
||||
var (
|
||||
ctx = gctx.GetInitCtx()
|
||||
)
|
||||
g.Log().Debug(ctx, "module base init start ...")
|
||||
cool.Loger.Debug(ctx, "module base init start ...")
|
||||
var t bool
|
||||
cool.FillInitData(ctx, "base", &model.BaseSysMenu{}, &t)
|
||||
|
||||
@@ -79,7 +79,7 @@ func init() {
|
||||
|
||||
// -- 执行函数
|
||||
// SELECT reset_all_sequences();`, nil) //重置所有序列
|
||||
g.Log().Debug(ctx, "module base init finished ...")
|
||||
cool.Loger.Debug(ctx, "module base init finished ...")
|
||||
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ func ResetAllSequences(ctx context.Context) error {
|
||||
|
||||
maxValueRecord, err := g.DB("default").Query(ctx, maxValueQuery)
|
||||
if err != nil {
|
||||
g.Log().Warning(ctx, fmt.Sprintf("获取表 %s.%s 的最大值失败: %v",
|
||||
cool.Loger.Warning(ctx, fmt.Sprintf("获取表 %s.%s 的最大值失败: %v",
|
||||
schemaName, tableName, err))
|
||||
continue
|
||||
}
|
||||
@@ -141,12 +141,12 @@ func ResetAllSequences(ctx context.Context) error {
|
||||
|
||||
_, err = g.DB("default").Exec(ctx, resetQuery)
|
||||
if err != nil {
|
||||
g.Log().Warning(ctx, fmt.Sprintf("重置序列 %s.%s 失败: %v",
|
||||
cool.Loger.Warning(ctx, fmt.Sprintf("重置序列 %s.%s 失败: %v",
|
||||
schemaName, sequenceName, err))
|
||||
continue
|
||||
}
|
||||
|
||||
g.Log().Info(ctx, fmt.Sprintf("序列 %s.%s 已重置为 %d",
|
||||
cool.Loger.Info(ctx, fmt.Sprintf("序列 %s.%s 已重置为 %d",
|
||||
schemaName, sequenceName, maxValue))
|
||||
}
|
||||
|
||||
|
||||
@@ -81,5 +81,5 @@ func init() {
|
||||
if jwtSecret == "cool-admin-go" {
|
||||
Config.Jwt.Secret = cool.ProcessFlag
|
||||
}
|
||||
g.Log().Info(ctx, "jwt secret:", Config.Jwt.Secret)
|
||||
cool.Loger.Info(ctx, "jwt secret:", Config.Jwt.Secret)
|
||||
}
|
||||
|
||||
@@ -42,13 +42,13 @@ type BaseOpenEpsReq struct {
|
||||
// eps 接口
|
||||
func (c *BaseOpen) Eps(ctx context.Context, req *BaseOpenEpsReq) (res *cool.BaseRes, err error) {
|
||||
if !cool.Config.Eps {
|
||||
g.Log().Error(ctx, "eps is not open")
|
||||
cool.Loger.Error(ctx, "eps is not open")
|
||||
res = cool.Ok(nil)
|
||||
return
|
||||
}
|
||||
data, err := c.baseOpenService.AdminEPS(ctx)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "eps error", err)
|
||||
cool.Loger.Error(ctx, "eps error", err)
|
||||
return cool.Fail(err.Error()), err
|
||||
}
|
||||
res = cool.Ok(data)
|
||||
|
||||
@@ -34,14 +34,14 @@ type BaseCommControllerEpsReq struct {
|
||||
// eps 接口
|
||||
func (c *BaseCommController) Eps(ctx context.Context, req *BaseCommControllerEpsReq) (res *cool.BaseRes, err error) {
|
||||
if !cool.Config.Eps {
|
||||
g.Log().Error(ctx, "eps is not open")
|
||||
cool.Loger.Error(ctx, "eps is not open")
|
||||
res = cool.Ok(nil)
|
||||
return
|
||||
}
|
||||
baseOpenService := service.NewBaseOpenService()
|
||||
data, err := baseOpenService.AppEPS(ctx)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "eps error", err)
|
||||
cool.Loger.Error(ctx, "eps error", err)
|
||||
return cool.Fail(err.Error()), err
|
||||
}
|
||||
res = cool.Ok(data)
|
||||
|
||||
@@ -13,7 +13,7 @@ type BaseFuncClearLog struct {
|
||||
|
||||
// Func
|
||||
func (f *BaseFuncClearLog) Func(ctx g.Ctx, param string) (err error) {
|
||||
g.Log().Info(ctx, "清理日志 BaseFuncClearLog.Func", "param", param)
|
||||
cool.Loger.Info(ctx, "清理日志 BaseFuncClearLog.Func", "param", param)
|
||||
baseSysLogService := service.NewBaseSysLogService()
|
||||
if param == "true" {
|
||||
err = baseSysLogService.Clear(true)
|
||||
|
||||
@@ -48,7 +48,7 @@ func BaseAuthorityMiddleware(r *ghttp.Request) {
|
||||
return []byte(config.Config.Jwt.Secret), nil
|
||||
})
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "BaseAuthorityMiddleware", err)
|
||||
cool.Loger.Error(ctx, "BaseAuthorityMiddleware", err)
|
||||
statusCode = 401
|
||||
r.Response.WriteStatusExit(statusCode, g.Map{
|
||||
"code": 1001,
|
||||
@@ -56,7 +56,7 @@ func BaseAuthorityMiddleware(r *ghttp.Request) {
|
||||
})
|
||||
}
|
||||
if !token.Valid {
|
||||
g.Log().Error(ctx, "BaseAuthorityMiddleware", "token invalid")
|
||||
cool.Loger.Error(ctx, "BaseAuthorityMiddleware", "token invalid")
|
||||
statusCode = 401
|
||||
r.Response.WriteStatusExit(statusCode, g.Map{
|
||||
"code": 1001,
|
||||
@@ -72,7 +72,7 @@ func BaseAuthorityMiddleware(r *ghttp.Request) {
|
||||
// 超管拥有所有权限
|
||||
if admin.UserId == 10001 && !admin.IsRefresh {
|
||||
if tokenString != rtoken && config.Config.Jwt.Sso {
|
||||
g.Log().Error(ctx, "BaseAuthorityMiddleware", "token invalid")
|
||||
cool.Loger.Error(ctx, "BaseAuthorityMiddleware", "token invalid")
|
||||
statusCode = 401
|
||||
r.Response.WriteStatusExit(statusCode, g.Map{
|
||||
"code": 1001,
|
||||
@@ -91,7 +91,7 @@ func BaseAuthorityMiddleware(r *ghttp.Request) {
|
||||
}
|
||||
// 如果传的token是refreshToken则校验失败
|
||||
if admin.IsRefresh {
|
||||
g.Log().Error(ctx, "BaseAuthorityMiddleware", "token invalid")
|
||||
cool.Loger.Error(ctx, "BaseAuthorityMiddleware", "token invalid")
|
||||
statusCode = 401
|
||||
r.Response.WriteStatusExit(statusCode, g.Map{
|
||||
"code": 1001,
|
||||
@@ -101,7 +101,7 @@ func BaseAuthorityMiddleware(r *ghttp.Request) {
|
||||
// 判断密码版本是否正确
|
||||
passwordV, _ := cool.CacheManager.Get(ctx, "admin:passwordVersion:"+gconv.String(admin.UserId))
|
||||
if passwordV.Int32() != *admin.PasswordVersion {
|
||||
g.Log().Error(ctx, "BaseAuthorityMiddleware", "passwordV invalid")
|
||||
cool.Loger.Error(ctx, "BaseAuthorityMiddleware", "passwordV invalid")
|
||||
statusCode = 401
|
||||
r.Response.WriteStatusExit(statusCode, g.Map{
|
||||
"code": 1001,
|
||||
@@ -110,7 +110,7 @@ func BaseAuthorityMiddleware(r *ghttp.Request) {
|
||||
}
|
||||
// 如果rtoken为空
|
||||
if rtoken == "" {
|
||||
g.Log().Error(ctx, "BaseAuthorityMiddleware", "rtoken invalid")
|
||||
cool.Loger.Error(ctx, "BaseAuthorityMiddleware", "rtoken invalid")
|
||||
statusCode = 401
|
||||
r.Response.WriteStatusExit(statusCode, g.Map{
|
||||
"code": 1001,
|
||||
@@ -119,7 +119,7 @@ func BaseAuthorityMiddleware(r *ghttp.Request) {
|
||||
}
|
||||
// 如果rtoken不等于token 且 sso 未开启
|
||||
if tokenString != rtoken && !config.Config.Jwt.Sso {
|
||||
g.Log().Error(ctx, "BaseAuthorityMiddleware", "token invalid")
|
||||
cool.Loger.Error(ctx, "BaseAuthorityMiddleware", "token invalid")
|
||||
statusCode = 401
|
||||
r.Response.WriteStatusExit(statusCode, g.Map{
|
||||
"code": 1001,
|
||||
@@ -134,7 +134,7 @@ func BaseAuthorityMiddleware(r *ghttp.Request) {
|
||||
perms := garray.NewStrArrayFrom(permsVar)
|
||||
// 如果perms为空
|
||||
if perms.Len() == 0 {
|
||||
g.Log().Error(ctx, "BaseAuthorityMiddleware", "perms invalid")
|
||||
cool.Loger.Error(ctx, "BaseAuthorityMiddleware", "perms invalid")
|
||||
statusCode = 403
|
||||
r.Response.WriteStatusExit(statusCode, g.Map{
|
||||
"code": 1001,
|
||||
@@ -154,7 +154,7 @@ func BaseAuthorityMiddleware(r *ghttp.Request) {
|
||||
url = gstr.Join(urls, ":")
|
||||
// 如果perms中不包含url 则无权限
|
||||
if !perms.ContainsI(url) {
|
||||
g.Log().Error(ctx, "BaseAuthorityMiddleware", "perms invalid")
|
||||
cool.Loger.Error(ctx, "BaseAuthorityMiddleware", "perms invalid")
|
||||
statusCode = 403
|
||||
r.Response.WriteStatusExit(statusCode, g.Map{
|
||||
"code": 1001,
|
||||
|
||||
@@ -65,7 +65,7 @@ func init() {
|
||||
// }
|
||||
// t, _ := service.NewBaseSysUserService().Person(admin.UserID)
|
||||
|
||||
//g.Log().Debug(context.TODO(), t.Mimi)
|
||||
//Loger.Debug(context.TODO(), t.Mimi)
|
||||
// session.Store("name", t.Mimi)
|
||||
//session.Store("key", r.Header.Get("Sec-WebSocket-Key"))
|
||||
return true
|
||||
|
||||
@@ -83,7 +83,7 @@ func (*BaseSysLoginService) Captcha(req *v1.BaseOpenCaptchaReq) (interface{}, er
|
||||
result.Data = `data:image/svg+xml;base64,` + svgbase64
|
||||
result.CaptchaId = guid.S()
|
||||
cool.CacheManager.Set(ctx, result.CaptchaId, captchaText, 1800*time.Second)
|
||||
g.Log().Debug(ctx, "验证码", result.CaptchaId, captchaText)
|
||||
cool.Loger.Debug(ctx, "验证码", result.CaptchaId, captchaText)
|
||||
return result, err
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func (s *BaseSysLoginService) RefreshToken(ctx context.Context, token string) (r
|
||||
func (*BaseSysLoginService) generateToken(ctx context.Context, user *model.BaseSysUser, roleIds []string, exprire uint, isRefresh bool) (token string) {
|
||||
err := cool.CacheManager.Set(ctx, "admin:passwordVersion:"+gconv.String(user.ID), gconv.String(user.PasswordV), 0)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "生成token失败", err)
|
||||
cool.Loger.Error(ctx, "生成token失败", err)
|
||||
}
|
||||
|
||||
claims := &cool.Claims{
|
||||
@@ -161,7 +161,7 @@ func (*BaseSysLoginService) generateToken(ctx context.Context, user *model.BaseS
|
||||
|
||||
token, err = tokenClaims.SignedString([]byte(config.Config.Jwt.Secret))
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "生成token失败", err)
|
||||
cool.Loger.Error(ctx, "生成token失败", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
_ "blazing/modules/dict/packed"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
|
||||
_ "blazing/modules/dict/controller"
|
||||
@@ -16,8 +15,8 @@ func init() {
|
||||
var (
|
||||
ctx = gctx.GetInitCtx()
|
||||
)
|
||||
g.Log().Debug(ctx, "module dict init start ...")
|
||||
cool.Loger.Debug(ctx, "module dict init start ...")
|
||||
cool.FillInitData(ctx, "dict", &model.DictInfo{}, nil)
|
||||
cool.FillInitData(ctx, "dict", &model.DictType{}, nil)
|
||||
g.Log().Debug(ctx, "module dict init finished ...")
|
||||
cool.Loger.Debug(ctx, "module dict init finished ...")
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package demo
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
_ "blazing/modules/space/controller"
|
||||
_ "blazing/modules/space/middleware"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
@@ -12,6 +12,6 @@ func init() {
|
||||
var (
|
||||
ctx = gctx.GetInitCtx()
|
||||
)
|
||||
g.Log().Debug(ctx, "module space init start ...")
|
||||
g.Log().Debug(ctx, "module space init finished ...")
|
||||
cool.Loger.Debug(ctx, "module space init start ...")
|
||||
cool.Loger.Debug(ctx, "module space init finished ...")
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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("任务执行成功"))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ...")
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user