Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6bf054e1e8 | ||
![]() |
a48afa14b7 | ||
![]() |
3b335785a4 |
30
log/log.go
30
log/log.go
@@ -24,22 +24,22 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type LogInfo struct {
|
type LogInfo struct {
|
||||||
InfoType LogType `json:"info_type"` // 日志类型,按被操作对象划分
|
LogType LogType `json:"log_type"` // 日志类型,按被操作对象划分
|
||||||
Operator *Operator `json:"operator,omitempty"` // 操作人,系统操作不用填写操作人,写日志类型就可以
|
Operator *Operator `json:"operator,omitempty"` // 操作人,系统操作不用填写操作人,写日志类型就可以
|
||||||
ObjectorID int `json:"objector_id,omitempty"` // 被操作对象ID,如果是gps,短信等服务则为0
|
ObjectorID int `json:"objector_id,omitempty"` // 被操作对象ID,如果是gps,短信等服务则为0
|
||||||
Title string `json:"title"` // 必填,标题,做什么事情
|
Title string `json:"title"` // 必填,标题,做什么事情
|
||||||
Param interface{} `json:"param,omitempty"` // 参数,请求参数,传指针
|
Param interface{} `json:"param,omitempty"` // 参数,请求参数,传指针
|
||||||
Result interface{} `json:"result,omitempty"` // 结果,返回值,传指针,如果是报错,传err
|
Result interface{} `json:"result,omitempty"` // 结果,返回值,传指针,如果是报错,传err
|
||||||
ErrStr string `json:"err_str,omitempty"` // 错误信息
|
ErrStr string `json:"err_str,omitempty"` // 错误信息,不用传入,自动记录
|
||||||
At string `json:"at"` // 记录时间,不用传入,自动记录
|
At string `json:"at"` // 记录时间,不用传入,自动记录
|
||||||
}
|
}
|
||||||
|
|
||||||
type OperatorType = string
|
type OperatorType = string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AdminOperatorType OperatorType = "admin" // 管理员
|
OperatorTypeAdmin OperatorType = "admin" // 管理员
|
||||||
MerchantOperatorType OperatorType = "merchant" // 商家
|
OperatorTypeMerchant OperatorType = "merchant" // 商家
|
||||||
UserOperatorType OperatorType = "user" // 用户
|
OperatorTypeUser OperatorType = "user" // 用户
|
||||||
)
|
)
|
||||||
|
|
||||||
type Operator struct {
|
type Operator struct {
|
||||||
@@ -114,3 +114,23 @@ func GFFatal(ctx context.Context, log *LogInfo) {
|
|||||||
handleLog(log)
|
handleLog(log)
|
||||||
g.Log().Fatal(ctx, log)
|
g.Log().Fatal(ctx, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *LogInfo) GFCommonHandelResult(ctx context.Context, result interface{}, err error) {
|
||||||
|
if err != nil {
|
||||||
|
l.Result = err
|
||||||
|
GFError(ctx, l)
|
||||||
|
} else {
|
||||||
|
l.Result = result
|
||||||
|
GFInfo(ctx, l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LogInfo) ZapCommonHandelResult(logger *zap.Logger, result interface{}, err error) {
|
||||||
|
if err != nil {
|
||||||
|
l.Result = err
|
||||||
|
ZapError(logger, l)
|
||||||
|
} else {
|
||||||
|
l.Result = result
|
||||||
|
ZapInfo(logger, l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user