imp: redirect go-ethereum's logs to cosmos logger (#948)

* redirect go-ethereum's logs to cosmos logger

Closes: #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
This commit is contained in:
yihuang 2022-02-19 08:49:34 +08:00 committed by GitHub
parent 0f5b1aa929
commit dcd2891b73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -35,6 +35,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
# Changelog # Changelog
## Unreleased
### Improvements
- (log) [#948](https://github.com/tharsis/ethermint/pull/948) redirect go-ethereum's logs to cosmos-sdk logger.
## [v0.10.0-beta1] - 2022-02-15 ## [v0.10.0-beta1] - 2022-02-15
### API Breaking ### API Breaking

View File

@ -10,6 +10,7 @@ import (
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/server/types"
ethlog "github.com/ethereum/go-ethereum/log"
ethrpc "github.com/ethereum/go-ethereum/rpc" ethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/tharsis/ethermint/rpc" "github.com/tharsis/ethermint/rpc"
@ -20,6 +21,19 @@ import (
func StartJSONRPC(ctx *server.Context, clientCtx client.Context, tmRPCAddr, tmEndpoint string, config config.Config) (*http.Server, chan struct{}, error) { 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) 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() rpcServer := ethrpc.NewServer()
rpcAPIArr := config.JSONRPC.API rpcAPIArr := config.JSONRPC.API