Skip to content

Commit

Permalink
redirect go-ethereum's logs to cosmos logger
Browse files Browse the repository at this point in the history
Closes: evmos#862

Map go-ethereum's log levels to cosmos ones:
trace -> debug
debug -> debug
info -> info
warn -> info
error -> error
crit -> error
  • Loading branch information
yihuang committed Feb 18, 2022
1 parent 0f5b1aa commit 44ea3ce
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions server/json_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/types"
ethlog "github.com/ethereum/go-ethereum/log"
ethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/tharsis/ethermint/rpc"

Expand All @@ -20,6 +21,25 @@ import (
func StartJSONRPC(ctx *server.Context, clientCtx client.Context, tmRPCAddr, tmEndpoint string, config config.Config) (*http.Server, chan struct{}, error) {
tmWsClient := ConnectTmWS(tmRPCAddr, tmEndpoint, ctx.Logger)

logger := ctx.Logger.With("module", "geth")
ethlog.Root().SetHandler(ethlog.FuncHandler(func(r *ethlog.Record) error {
switch r.Lvl {
case ethlog.LvlTrace:
fallthrough
case ethlog.LvlDebug:
logger.Debug(r.Msg, r.Ctx...)
case ethlog.LvlInfo:
logger.Info(r.Msg, r.Ctx...)
case ethlog.LvlWarn:
logger.Info(r.Msg, r.Ctx...)
case ethlog.LvlError:
logger.Error(r.Msg, r.Ctx...)
case ethlog.LvlCrit:
logger.Error(r.Msg, r.Ctx...)
}
return nil
}))

rpcServer := ethrpc.NewServer()

rpcAPIArr := config.JSONRPC.API
Expand Down

0 comments on commit 44ea3ce

Please sign in to comment.