Skip to content

Commit

Permalink
rpc daemon: log request params on debug verbosity (#1087)
Browse files Browse the repository at this point in the history
* rpc_daemon_access_log

* rpc_daemon_access_log

* clean

* remove response

* remove accesslog concept

* clean
  • Loading branch information
AskAlexSharov committed Sep 9, 2020
1 parent bdb7832 commit 84b52a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
6 changes: 2 additions & 4 deletions cmd/rpcdaemon/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package cli
import (
"context"
"fmt"
"net/http"

"github.com/ledgerwatch/turbo-geth/cmd/utils"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/internal/debug"
"github.com/ledgerwatch/turbo-geth/log"
"github.com/ledgerwatch/turbo-geth/node"
"github.com/ledgerwatch/turbo-geth/rpc"
"github.com/spf13/cobra"
"net/http"
)

type Flags struct {
Expand Down Expand Up @@ -103,8 +102,7 @@ func StartRpcServer(ctx context.Context, cfg Flags, rpcAPI []rpc.API) error {
wsHandler = srv.WebsocketHandler([]string{"*"})
}

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if cfg.WebsocketEnabled && r.Method == "GET" {
wsHandler.ServeHTTP(w, r)
}
Expand Down
9 changes: 4 additions & 5 deletions rpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,21 +292,20 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMess
switch {
case msg.isNotification():
h.handleCall(ctx, msg)
h.log.Debug("Served "+msg.Method, "t", time.Since(start))
h.log.Debug("Served", "t", time.Since(start), "method", msg.Method, "params", string(msg.Params))
return nil
case msg.isCall():
resp := h.handleCall(ctx, msg)
var ctx []interface{}
ctx = append(ctx, "reqid", idForLog{msg.ID}, "t", time.Since(start))
ctx = append(ctx, "method", msg.Method, "reqid", idForLog{msg.ID}, "t", time.Since(start))
if resp.Error != nil {
ctx = append(ctx, "err", resp.Error.Message)
if resp.Error.Data != nil {
ctx = append(ctx, "errdata", resp.Error.Data)
}
h.log.Warn("Served "+msg.Method, ctx...)
} else {
h.log.Debug("Served "+msg.Method, ctx...)
h.log.Warn("Served", ctx...)
}
h.log.Debug("Served", "t", time.Since(start), "method", msg.Method, "reqid", idForLog{msg.ID}, "params", string(msg.Params))
return resp
case msg.hasValidID():
return msg.errorResponse(&invalidRequestError{"invalid request"})
Expand Down

0 comments on commit 84b52a5

Please sign in to comment.