diff options
author | Alexander Kiryukhin <i@neonxp.dev> | 2022-06-30 03:07:26 +0300 |
---|---|---|
committer | Alexander Kiryukhin <i@neonxp.dev> | 2022-06-30 03:14:21 +0300 |
commit | 058331685cbdb73a4610110eb5599c0628e51c26 (patch) | |
tree | b263869eeeafe748d65dd1c5f7b56e4167969030 /rpc | |
parent | c39fcbc6a153b11354fa46e69a332ebc3774fdcb (diff) |
Better logging
Diffstat (limited to 'rpc')
-rw-r--r-- | rpc/middleware/logger.go | 10 |
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, ¶ms); 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 } } |