Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a5cb0496c0 | ||
![]() |
9b838fd5d9 | ||
![]() |
a1b4fe772c | ||
![]() |
431fd441a7 | ||
![]() |
f6a19bd7e9 | ||
![]() |
07ff135eea | ||
![]() |
eeed182985 | ||
![]() |
d233f3a1a3 |
12
go.sum
12
go.sum
@@ -1,12 +0,0 @@
|
|||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/dromara/carbon/v2 v2.6.4 h1:cpIansyiEIEed3OlEIqo1IXj86qu0x6pf/E2keL2wYo=
|
|
||||||
github.com/dromara/carbon/v2 v2.6.4/go.mod h1:Baj3A1uBBctJmpZWJd6/+WWnmIuY2pobR6IOpB6xigc=
|
|
||||||
github.com/gogf/gf/v2 v2.7.2/go.mod h1:EBXneAg/wes86rfeh68XC0a2JBNQylmT7Sp6/8Axk88=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
|
||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
|
||||||
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
|
|
||||||
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
|
||||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
|
||||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
114
log/log.go
114
log/log.go
@@ -6,34 +6,29 @@ import (
|
|||||||
"github.com/dromara/carbon/v2"
|
"github.com/dromara/carbon/v2"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LogType = string
|
type LogType = string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LogTypeOrder LogType = "order" // 订单
|
LogTypeOrder LogType = "order" // 订单
|
||||||
LogTypeProduct LogType = "product" // 商品
|
LogTypeProduct LogType = "product" // 商品
|
||||||
LogTypeMerchant LogType = "merchant" // 商家
|
LogTypeMerchant LogType = "merchant" // 商家
|
||||||
LogTypeMerchantUser LogType = "merchant_user" // 商家用户
|
LogTypeMerchantRedPack LogType = "merchant_red_pack" // 商家红包
|
||||||
LogTypePay LogType = "pay" // 支付
|
LogTypePay LogType = "pay" // 支付
|
||||||
LogTypeUser LogType = "user" // 用户
|
LogTypeUser LogType = "user" // 用户
|
||||||
LogTypeGPS LogType = "gps" // gps
|
LogTypeUserRedPack LogType = "user_red_pack" // 用户红包
|
||||||
LogTypeSMS LogType = "sms" // 短信
|
LogTypeGPS LogType = "gps" // gps
|
||||||
LogTypeIP LogType = "ip" // ip信息
|
LogTypeSMS LogType = "sms" // 短信
|
||||||
LogTypeSystem LogType = "system" // 系统、日志、定时任务初始化、定时任务、mq初始化等
|
LogTypeIP LogType = "ip" // ip信息
|
||||||
|
LogTypeAdmin LogType = "admin" // 管理员操作,例如登录、退出、修改密码、修改用户信息、修改角色信息、审核等
|
||||||
|
LogTypeSystem LogType = "system" // 系统、日志、定时任务初始化、定时任务、mq初始化等
|
||||||
|
LogTypeSystemRedPack LogType = "system_red_pack" // 系统红包
|
||||||
|
LogTypeActivity LogType = "activity" // 活动
|
||||||
|
LogTypeJJT LogType = "jjt" // 交易所
|
||||||
)
|
)
|
||||||
|
|
||||||
type LogInfo struct {
|
|
||||||
LogType LogType `json:"log_type"` // 日志类型,按被操作对象划分
|
|
||||||
Operator *Operator `json:"operator,omitempty"` // 操作人,系统操作不用填写操作人,写日志类型就可以
|
|
||||||
ObjectorID int `json:"objector_id,omitempty"` // 被操作对象ID,如果是gps,短信等服务则为0
|
|
||||||
Title string `json:"title"` // 必填,标题,做什么事情
|
|
||||||
Param interface{} `json:"param,omitempty"` // 参数,请求参数,传指针
|
|
||||||
Result interface{} `json:"result,omitempty"` // 结果,返回值,传指针,如果是报错,传err
|
|
||||||
ErrStr string `json:"err_str,omitempty"` // 错误信息,不用传入,自动记录
|
|
||||||
At string `json:"at"` // 记录时间,不用传入,自动记录
|
|
||||||
}
|
|
||||||
|
|
||||||
type OperatorType = string
|
type OperatorType = string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -47,71 +42,104 @@ type Operator struct {
|
|||||||
OperatorType OperatorType
|
OperatorType OperatorType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LogInfo struct {
|
||||||
|
LogType LogType `json:"log_type"` // 日志类型,按被操作对象划分
|
||||||
|
Operator *Operator `json:"operator,omitempty"` // 操作人,系统操作不用填写操作人,写日志类型就可以
|
||||||
|
ObjectorID int `json:"objector_id,omitempty"` // 被操作对象ID,如果是gps,短信等服务则为0
|
||||||
|
Title string `json:"title"` // 必填,标题,做什么事情
|
||||||
|
Param interface{} `json:"param,omitempty"` // 参数,请求参数,传指针
|
||||||
|
Result interface{} `json:"result,omitempty"` // 结果,返回值,传指针,如果是报错,传err
|
||||||
|
ErrStr string `json:"err_str,omitempty"` // 错误信息,不用传入,自动记录
|
||||||
|
At string `json:"at"` // 记录时间,不用传入,自动记录
|
||||||
|
Timestamp int64 `json:"timestamp"` // 时间戳,不用传入,自动记录
|
||||||
|
}
|
||||||
|
|
||||||
|
type param struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Value interface{} `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type result struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Value interface{} `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
func ZapDebug(logger *zap.Logger, log *LogInfo) {
|
func ZapDebug(logger *zap.Logger, log *LogInfo) {
|
||||||
handleLog(log)
|
HandleLog(log)
|
||||||
logger.Debug("", zap.Any("log", log))
|
logger.Debug("", zap.Any("log", log))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ZapInfo(logger *zap.Logger, log *LogInfo) {
|
func ZapInfo(logger *zap.Logger, log *LogInfo) {
|
||||||
handleLog(log)
|
HandleLog(log)
|
||||||
logger.Info("", zap.Any("log", log))
|
logger.Info("", zap.Any("log", log))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ZapWarn(logger *zap.Logger, log *LogInfo) {
|
func ZapWarn(logger *zap.Logger, log *LogInfo) {
|
||||||
handleLog(log)
|
HandleLog(log)
|
||||||
logger.Warn("", zap.Any("log", log))
|
logger.Warn("", zap.Any("log", log))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ZapError(logger *zap.Logger, log *LogInfo) {
|
func ZapError(logger *zap.Logger, log *LogInfo) {
|
||||||
handleLog(log)
|
HandleLog(log)
|
||||||
logger.Error("", zap.Any("log", log))
|
logger.Error("", zap.Any("log", log))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ZapPanic(logger *zap.Logger, log *LogInfo) {
|
func ZapPanic(logger *zap.Logger, log *LogInfo) {
|
||||||
handleLog(log)
|
HandleLog(log)
|
||||||
logger.Panic("", zap.Any("log", log))
|
logger.Panic("", zap.Any("log", log))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ZapFatal(logger *zap.Logger, log *LogInfo) {
|
func ZapFatal(logger *zap.Logger, log *LogInfo) {
|
||||||
handleLog(log)
|
HandleLog(log)
|
||||||
logger.Fatal("", zap.Any("log", log))
|
logger.Fatal("", zap.Any("log", log))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleLog(log *LogInfo) {
|
func HandleLog(log *LogInfo) {
|
||||||
log.At = carbon.Now().ToDateTimeString()
|
log.At = carbon.Now().ToDateTimeString()
|
||||||
if _, ok := log.Result.(error); ok {
|
log.Timestamp = carbon.Now().Timestamp()
|
||||||
log.ErrStr = fmt.Sprintf("%+v", log.Result)
|
// 处理 Param
|
||||||
log.Result = nil
|
// 处理 Param
|
||||||
|
if log.Param != nil {
|
||||||
|
log.Param = processValue(log.Param)
|
||||||
|
}
|
||||||
|
// 处理 Result
|
||||||
|
if log.Result != nil {
|
||||||
|
if _, ok := log.Result.(error); ok {
|
||||||
|
log.ErrStr = fmt.Sprintf("%+v", log.Result)
|
||||||
|
log.Result = nil
|
||||||
|
} else {
|
||||||
|
log.Result = processValue(log.Result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GFInfo(ctx context.Context, log *LogInfo) {
|
func GFInfo(ctx context.Context, log *LogInfo) {
|
||||||
handleLog(log)
|
HandleLog(log)
|
||||||
g.Log().Info(ctx, log)
|
g.Log().Info(ctx, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GFWarning(ctx context.Context, log *LogInfo) {
|
func GFWarning(ctx context.Context, log *LogInfo) {
|
||||||
handleLog(log)
|
HandleLog(log)
|
||||||
g.Log().Warning(ctx, log)
|
g.Log().Warning(ctx, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GFError(ctx context.Context, log *LogInfo) {
|
func GFError(ctx context.Context, log *LogInfo) {
|
||||||
handleLog(log)
|
HandleLog(log)
|
||||||
g.Log().Error(ctx, log)
|
g.Log().Error(ctx, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GFDebug(ctx context.Context, log *LogInfo) {
|
func GFDebug(ctx context.Context, log *LogInfo) {
|
||||||
handleLog(log)
|
HandleLog(log)
|
||||||
g.Log().Debug(ctx, log)
|
g.Log().Debug(ctx, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GFPanic(ctx context.Context, log *LogInfo) {
|
func GFPanic(ctx context.Context, log *LogInfo) {
|
||||||
handleLog(log)
|
HandleLog(log)
|
||||||
g.Log().Panic(ctx, log)
|
g.Log().Panic(ctx, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GFFatal(ctx context.Context, log *LogInfo) {
|
func GFFatal(ctx context.Context, log *LogInfo) {
|
||||||
handleLog(log)
|
HandleLog(log)
|
||||||
g.Log().Fatal(ctx, log)
|
g.Log().Fatal(ctx, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,3 +162,15 @@ func (l *LogInfo) ZapCommonHandelResult(logger *zap.Logger, result interface{},
|
|||||||
ZapInfo(logger, l)
|
ZapInfo(logger, l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func processValue(value interface{}) interface{} {
|
||||||
|
kind := reflect.TypeOf(value).Kind()
|
||||||
|
switch kind {
|
||||||
|
case reflect.Map, reflect.Slice, reflect.Array, reflect.Struct:
|
||||||
|
// 如果是复杂类型,保持原样
|
||||||
|
return value
|
||||||
|
default:
|
||||||
|
// 对于其他类型,转换为字符串
|
||||||
|
return param{Type: kind.String(), Value: fmt.Sprintf("%v", value)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
5
rabbitmq_user.go
Normal file
5
rabbitmq_user.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package common_structure
|
||||||
|
|
||||||
|
type UserLogout struct {
|
||||||
|
UserID uint `json:"user_id"`
|
||||||
|
}
|
Reference in New Issue
Block a user