日志参数和结果转对象

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

View File

@@ -99,18 +99,14 @@ func HandleLog(log *LogInfo) {
log.Timestamp = carbon.Now().Timestamp()
// 处理 Param
// 处理 Param
if log.Param != nil {
log.Param = processValue(log.Param)
}
// 处理 Result
if log.Result != nil {
if _, ok := log.Result.(error); ok {
log.ErrStr = fmt.Sprintf("%+v", log.Result)
log.Result = nil
log.Result = struct{}{}
} else {
log.Result = processValue(log.Result)
}
}
}
func GFInfo(ctx context.Context, log *LogInfo) {
@@ -164,6 +160,9 @@ 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: