日志参数转字符串
This commit is contained in:
11
log/log.go
11
log/log.go
@@ -3,7 +3,6 @@ package log
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"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"
|
||||||
)
|
)
|
||||||
@@ -48,9 +47,6 @@ type LogInfo struct {
|
|||||||
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"` // 错误信息,不用传入,自动记录
|
|
||||||
At string `json:"at"` // 记录时间,不用传入,自动记录
|
|
||||||
Timestamp int64 `json:"timestamp"` // 时间戳,不用传入,自动记录
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type param struct {
|
type param struct {
|
||||||
@@ -94,17 +90,10 @@ func ZapFatal(logger *zap.Logger, log *LogInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandleLog(log *LogInfo) {
|
func HandleLog(log *LogInfo) {
|
||||||
log.At = carbon.Now().ToDateTimeString()
|
|
||||||
log.Timestamp = carbon.Now().Timestamp()
|
|
||||||
// 处理 Param
|
// 处理 Param
|
||||||
log.Param = processValue(log.Param)
|
log.Param = processValue(log.Param)
|
||||||
// 处理 Result
|
// 处理 Result
|
||||||
if _, ok := log.Result.(error); ok {
|
|
||||||
log.ErrStr = fmt.Sprintf("%+v", log.Result)
|
|
||||||
log.Result = struct{}{}
|
|
||||||
} else {
|
|
||||||
log.Result = processValue(log.Result)
|
log.Result = processValue(log.Result)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GFInfo(ctx context.Context, log *LogInfo) {
|
func GFInfo(ctx context.Context, log *LogInfo) {
|
||||||
|
Reference in New Issue
Block a user