From 9cd7b9ce29250595fb63356bc3919742fbd7a1ce Mon Sep 17 00:00:00 2001 From: jongwhan lee Date: Tue, 27 Jul 2021 16:13:05 +0900 Subject: [PATCH] fix eth log override remove redundant log tidy up --- log/handler.go | 70 +++++++++---------------------------------------- server/start.go | 1 - 2 files changed, 12 insertions(+), 59 deletions(-) diff --git a/log/handler.go b/log/handler.go index 900b099555..658170b026 100644 --- a/log/handler.go +++ b/log/handler.go @@ -1,76 +1,30 @@ package log import ( - "github.com/rs/zerolog" + "fmt" - "github.com/cosmos/cosmos-sdk/server" ethlog "github.com/ethereum/go-ethereum/log" tmlog "github.com/tendermint/tendermint/libs/log" ) -var _ ethlog.Handler = &Handler{} +var ethermintLogger *tmlog.Logger = nil -// Logger wraps the zero log Wrapper and extends it to support the ethereum logger interface. -type Handler struct { - *server.ZeroLogWrapper +func FuncHandler(fn func(r *ethlog.Record) error) ethlog.Handler { + return funcHandler(fn) } -func NewHandler(logger tmlog.Logger) ethlog.Handler { - zerologger, ok := logger.(*server.ZeroLogWrapper) - if !ok { - // default to Stdout if not an SDK logger wrapper - return ethlog.StdoutHandler - } +type funcHandler func(r *ethlog.Record) error - return &Handler{ - ZeroLogWrapper: zerologger, - } +func (h funcHandler) Log(r *ethlog.Record) error { + return h(r) } -// Log implements the go-ethereum Logger Handler interface -func (h *Handler) Log(r *ethlog.Record) error { - lvl := EthLogLvlToZerolog(r.Lvl) - - h.ZeroLogWrapper. - WithLevel(lvl). - Fields(getLogFields(r.Ctx...)). - Time(r.KeyNames.Time, r.Time). - Msg(r.Msg) - return nil -} - -func EthLogLvlToZerolog(lvl ethlog.Lvl) zerolog.Level { - var level zerolog.Level - - switch lvl { - case ethlog.LvlCrit: - level = zerolog.FatalLevel - case ethlog.LvlDebug: - level = zerolog.DebugLevel - case ethlog.LvlError: - level = zerolog.ErrorLevel - case ethlog.LvlInfo: - level = zerolog.InfoLevel - case ethlog.LvlTrace: - level = zerolog.TraceLevel - case ethlog.LvlWarn: - level = zerolog.WarnLevel - default: - level = zerolog.NoLevel - } +func NewHandler(logger tmlog.Logger) ethlog.Handler { - return level -} + ethermintLogger = &logger -func getLogFields(keyVals ...interface{}) map[string]interface{} { - if len(keyVals)%2 != 0 { + return FuncHandler(func(r *ethlog.Record) error { + (*ethermintLogger).Debug(fmt.Sprintf("[EVM] %v", r)) return nil - } - - fields := make(map[string]interface{}) - for i := 0; i < len(keyVals); i += 2 { - fields[keyVals[i].(string)] = keyVals[i+1] - } - - return fields + }) } diff --git a/server/start.go b/server/start.go index 26d678c9d1..e17d40818a 100644 --- a/server/start.go +++ b/server/start.go @@ -40,7 +40,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ethlog "github.com/ethereum/go-ethereum/log" - ethdebug "github.com/tharsis/ethermint/ethereum/rpc/namespaces/debug" "github.com/tharsis/ethermint/log" "github.com/tharsis/ethermint/server/config"