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
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
@@ -213,7 +212,7 @@ func Recv(c *entity.Conn, data handler.TomeeHeader) {
|
||||
|
||||
if ok && aa != nil { //这里实现回复错误包
|
||||
|
||||
g.Log().Error(context.Background(), aa.Error(), aa.Code())
|
||||
cool.Loger.Error(context.Background(), aa.Error(), aa.Code())
|
||||
|
||||
data.Result = uint32(aa.Code())
|
||||
c.SendPack(data.Pack(nil))
|
||||
|
||||
@@ -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