aboutsummaryrefslogtreecommitdiff
path: root/rpc/middleware/logger.go
diff options
context:
space:
mode:
Diffstat (limited to 'rpc/middleware/logger.go')
-rw-r--r--rpc/middleware/logger.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/rpc/middleware/logger.go b/rpc/middleware/logger.go
index dbf5a4d..507b570 100644
--- a/rpc/middleware/logger.go
+++ b/rpc/middleware/logger.go
@@ -21,7 +21,8 @@ package middleware
import (
"context"
- "strings"
+ "encoding/json"
+ "fmt"
"time"
"go.neonxp.dev/jsonrpc2/rpc"
@@ -33,8 +34,11 @@ func Logger(logger rpc.Logger) rpc.Middleware {
t1 := time.Now().UnixMicro()
resp := handler(ctx, req)
t2 := time.Now().UnixMicro()
- args := strings.ReplaceAll(string(req.Params), "\n", "")
- logger.Logf("rpc call=%s, args=%s, take=%dμs", req.Method, args, (t2 - t1))
+ var params any
+ if err := json.Unmarshal(req.Params, &params); err != nil {
+ params = fmt.Sprintf("<invalid body: %s>", err.Error())
+ }
+ logger.Logf("rpc call=%s, args=%+v, take=%dμs", req.Method, params, (t2 - t1))
return resp
}
}