Compare commits

..

3 Commits

Author SHA1 Message Date
yuguojian
7f0c64fd8a 日志参数转字符串 2025-07-15 15:26:59 +08:00
yuguojian
093b34f32f 日志参数转字符串 2025-07-14 15:51:53 +08:00
yuguojian
33e119864e 日志参数转字符串 2025-07-14 15:26:10 +08:00
2 changed files with 3 additions and 90 deletions

View File

@@ -1,75 +0,0 @@
{
"settings": {
"index": {
"mapping": {
"source": {
"mode": "synthetic"
}
}
}
},
"mappings": {
"properties": {
"caller": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"created_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis||epoch_second"
},
"level": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"log": {
"properties": {
"at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis||epoch_second"
},
"log_type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"param": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"result": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
}
}

View File

@@ -3,7 +3,6 @@ package log
import (
"context"
"fmt"
"github.com/dromara/carbon/v2"
"github.com/gogf/gf/v2/frame/g"
"go.uber.org/zap"
)
@@ -37,8 +36,8 @@ const (
)
type Operator struct {
ID int // 系统ID设置0
OperatorType OperatorType
ID int // 系统ID设置0
OperatorType OperatorType `json:"operator_type"`
}
type LogInfo struct {
@@ -48,9 +47,6 @@ type LogInfo struct {
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 {
@@ -94,17 +90,10 @@ func ZapFatal(logger *zap.Logger, log *LogInfo) {
}
func HandleLog(log *LogInfo) {
log.At = carbon.Now().ToDateTimeString()
log.Timestamp = carbon.Now().Timestamp()
// 处理 Param
log.Param = processValue(log.Param)
// 处理 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) {
@@ -161,6 +150,5 @@ func processValue(value interface{}) interface{} {
if value == nil {
return ""
}
// 对于其他类型,转换为字符串
return fmt.Sprintf("%+v", value)
}