Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

redirect go-ethereum's logs to cosmos logger #948

Merged
merged 4 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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:
yihuang marked this conversation as resolved.
Show resolved Hide resolved
logger.Debug(r.Msg, r.Ctx...)
case ethlog.LvlInfo:
logger.Info(r.Msg, r.Ctx...)
yihuang marked this conversation as resolved.
Show resolved Hide resolved
case ethlog.LvlWarn:
logger.Info(r.Msg, r.Ctx...)
case ethlog.LvlError:
logger.Error(r.Msg, r.Ctx...)
yihuang marked this conversation as resolved.
Show resolved Hide resolved
case ethlog.LvlCrit:
logger.Error(r.Msg, r.Ctx...)
}
return nil
}))

rpcServer := ethrpc.NewServer()

rpcAPIArr := config.JSONRPC.API
Expand Down