refactor(logging): 统一使用自定义Loger替代g.Log()日志记录
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user