From 058331685cbdb73a4610110eb5599c0628e51c26 Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Thu, 30 Jun 2022 03:07:26 +0300 Subject: Better logging --- rpc/middleware/logger.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'rpc') 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, ¶ms); err != nil { + params = fmt.Sprintf("", err.Error()) + } + logger.Logf("rpc call=%s, args=%+v, take=%dμs", req.Method, params, (t2 - t1)) return resp } } -- cgit v1.2.3