日志参数和结果转对象

This commit is contained in:
yuguojian
2025-07-10 10:18:37 +08:00
parent be976b73f6
commit e2dfb3e5ad

View File

@@ -99,17 +99,13 @@ func HandleLog(log *LogInfo) {
log.Timestamp = carbon.Now().Timestamp() log.Timestamp = carbon.Now().Timestamp()
// 处理 Param // 处理 Param
// 处理 Param // 处理 Param
if log.Param != nil { log.Param = processValue(log.Param)
log.Param = processValue(log.Param)
}
// 处理 Result // 处理 Result
if log.Result != nil { if _, ok := log.Result.(error); ok {
if _, ok := log.Result.(error); ok { log.ErrStr = fmt.Sprintf("%+v", log.Result)
log.ErrStr = fmt.Sprintf("%+v", log.Result) log.Result = struct{}{}
log.Result = nil } else {
} else { log.Result = processValue(log.Result)
log.Result = processValue(log.Result)
}
} }
} }
@@ -164,6 +160,9 @@ func (l *LogInfo) ZapCommonHandelResult(logger *zap.Logger, result interface{},
} }
func processValue(value interface{}) interface{} { func processValue(value interface{}) interface{} {
if value == nil {
return struct{}{}
}
kind := reflect.TypeOf(value).Kind() kind := reflect.TypeOf(value).Kind()
switch kind { switch kind {
case reflect.Map, reflect.Slice, reflect.Array, reflect.Struct: case reflect.Map, reflect.Slice, reflect.Array, reflect.Struct: