aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go.sum1
-rw-r--r--rpc/middleware/logger.go10
2 files changed, 8 insertions, 3 deletions
diff --git a/go.sum b/go.sum
index a886b78..28b48ac 100644
--- a/go.sum
+++ b/go.sum
@@ -4,6 +4,7 @@ github.com/qri-io/jsonpointer v0.1.1 h1:prVZBZLL6TW5vsSB9fFHFAMBLI4b0ri5vribQlTJ
github.com/qri-io/jsonpointer v0.1.1/go.mod h1:DnJPaYgiKu56EuDp8TU5wFLdZIcAnb/uH9v37ZaMV64=
github.com/qri-io/jsonschema v0.2.1 h1:NNFoKms+kut6ABPf6xiKNM5214jzxAhDBrPHCJ97Wg0=
github.com/qri-io/jsonschema v0.2.1/go.mod h1:g7DPkiOsK1xv6T/Ao5scXRkd+yTFygcANPBaaqW+VrI=
+github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
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
}
}