Skip to content

Commit

Permalink
imp: redirect go-ethereum's logs to cosmos logger (evmos#948)
Browse files Browse the repository at this point in the history
* redirect go-ethereum's logs to cosmos logger

Closes: evmos#862

Map go-ethereum's log levels to cosmos ones:
trace -> debug
debug -> debug
info -> info
warn -> info
error -> error
crit -> error

* changelog

* Apply suggestions from code review

* Apply suggestions from code review
  • Loading branch information
yihuang committed Mar 1, 2022
1 parent c627df4 commit aef3a14
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (config) [tharsis#908](https://github.com/tharsis/ethermint/pull/908) Add api.enable flag for Cosmos SDK Rest server
* (feemarket) [tharsis#919](https://github.com/tharsis/ethermint/pull/919) Initialize baseFee in default genesis state.
* (evm) [tharsis#932](https://github.com/tharsis/ethermint/pull/932) Fix base fee check logic in state transition.
* (log) [#948](https://github.com/tharsis/ethermint/pull/948) redirect go-ethereum's logs to cosmos-sdk logger.

### Bug Fixes

Expand Down
14 changes: 14 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,19 @@ 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, ethlog.LvlDebug:
logger.Debug(r.Msg, r.Ctx...)
case ethlog.LvlInfo, ethlog.LvlWarn:
logger.Info(r.Msg, r.Ctx...)
case ethlog.LvlError, ethlog.LvlCrit:
logger.Error(r.Msg, r.Ctx...)
}
return nil
}))

rpcServer := ethrpc.NewServer()

rpcAPIArr := config.JSONRPC.API
Expand Down

0 comments on commit aef3a14

Please sign in to comment.