|
|
@@ -2,9 +2,11 @@ package logging
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
"time"
|
|
|
|
|
|
+ "git.ikuban.com/server/kratos-utils/codes"
|
|
|
"github.com/go-kratos/kratos/v2/errors"
|
|
|
"github.com/go-kratos/kratos/v2/log"
|
|
|
"github.com/go-kratos/kratos/v2/middleware"
|
|
|
@@ -75,7 +77,6 @@ func Client(logger log.Logger) middleware.Middleware {
|
|
|
}
|
|
|
level, stack := extractError(err)
|
|
|
log.WithContext(ctx, logger).Log(level,
|
|
|
- "kind", "client",
|
|
|
"component", kind,
|
|
|
"operation", operation,
|
|
|
"args", extractArgs(req),
|
|
|
@@ -94,13 +95,17 @@ func extractArgs(req interface{}) string {
|
|
|
if stringer, ok := req.(fmt.Stringer); ok {
|
|
|
return stringer.String()
|
|
|
}
|
|
|
- return fmt.Sprintf("%+v", req)
|
|
|
+ j, err := json.Marshal(req)
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Sprintf("%+v", req)
|
|
|
+ }
|
|
|
+ return string(j)
|
|
|
}
|
|
|
|
|
|
// extractError returns the string of the error
|
|
|
func extractError(err error) (log.Level, string) {
|
|
|
if err != nil {
|
|
|
- return log.LevelError, fmt.Sprintf("%+v", err)
|
|
|
+ return log.LevelError, fmt.Sprintf("%+v", codes.ParseErrorMsg(err))
|
|
|
}
|
|
|
return log.LevelInfo, ""
|
|
|
}
|