From 44ea3ced53f6e63a7d52f401385636f619619116 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 18 Feb 2022 15:21:39 +0800 Subject: [PATCH 1/4] 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 --- server/json_rpc.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server/json_rpc.go b/server/json_rpc.go index 315cc850dc..27e386a50e 100644 --- a/server/json_rpc.go +++ b/server/json_rpc.go @@ -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" @@ -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 From 2db2b21e3adfaf5d7cbeaf698d34414b47b7771f Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 18 Feb 2022 15:30:31 +0800 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82e94a0d9b..39c64d9e3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,12 @@ Ref: https://keepachangelog.com/en/1.0.0/ # 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 ### API Breaking From 46cdd9fd01a8923cdbe12d1550cdf73133981d2b Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 18 Feb 2022 21:42:49 +0800 Subject: [PATCH 3/4] Apply suggestions from code review --- server/json_rpc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/json_rpc.go b/server/json_rpc.go index 27e386a50e..3c6434495c 100644 --- a/server/json_rpc.go +++ b/server/json_rpc.go @@ -29,11 +29,11 @@ func StartJSONRPC(ctx *server.Context, clientCtx client.Context, tmRPCAddr, tmEn case ethlog.LvlDebug: logger.Debug(r.Msg, r.Ctx...) case ethlog.LvlInfo: - logger.Info(r.Msg, r.Ctx...) + fallthrough case ethlog.LvlWarn: logger.Info(r.Msg, r.Ctx...) case ethlog.LvlError: - logger.Error(r.Msg, r.Ctx...) + fallthrough case ethlog.LvlCrit: logger.Error(r.Msg, r.Ctx...) } From e2412055a8718d1f62299d4b2b6f96bfd5b2bae0 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 18 Feb 2022 21:44:12 +0800 Subject: [PATCH 4/4] Apply suggestions from code review --- server/json_rpc.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/server/json_rpc.go b/server/json_rpc.go index 3c6434495c..4c893d714e 100644 --- a/server/json_rpc.go +++ b/server/json_rpc.go @@ -24,17 +24,11 @@ func StartJSONRPC(ctx *server.Context, clientCtx client.Context, tmRPCAddr, tmEn 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: + case ethlog.LvlTrace, ethlog.LvlDebug: logger.Debug(r.Msg, r.Ctx...) - case ethlog.LvlInfo: - fallthrough - case ethlog.LvlWarn: + case ethlog.LvlInfo, ethlog.LvlWarn: logger.Info(r.Msg, r.Ctx...) - case ethlog.LvlError: - fallthrough - case ethlog.LvlCrit: + case ethlog.LvlError, ethlog.LvlCrit: logger.Error(r.Msg, r.Ctx...) } return nil