日志参数转字符串

This commit is contained in:
yuguojian
2025-07-14 14:51:05 +08:00
parent 994ed9e639
commit f6a41a5e7c
3 changed files with 78 additions and 97 deletions

View File

@@ -6,7 +6,6 @@ import (
"github.com/dromara/carbon/v2"
"github.com/gogf/gf/v2/frame/g"
"go.uber.org/zap"
"reflect"
)
type LogType = string
@@ -98,7 +97,6 @@ func HandleLog(log *LogInfo) {
log.At = carbon.Now().ToDateTimeString()
log.Timestamp = carbon.Now().Timestamp()
// 处理 Param
// 处理 Param
log.Param = processValue(log.Param)
// 处理 Result
if _, ok := log.Result.(error); ok {
@@ -161,15 +159,8 @@ func (l *LogInfo) ZapCommonHandelResult(logger *zap.Logger, result interface{},
func processValue(value interface{}) interface{} {
if value == nil {
return struct{}{}
}
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)}
return ""
}
// 对于其他类型,转换为字符串
return fmt.Sprintf("%+v", value)
}