fix: remove unused code (#834)

Co-authored-by: Marko Baricevic <markobaricevic3778@gmail.com>
Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
Marko 2021-12-13 22:15:15 +01:00 committed by GitHub
parent 1737e654f1
commit 876d9cfee3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 185 deletions

View File

@ -1,35 +0,0 @@
package log
import (
"io"
"testing"
"github.com/cosmos/cosmos-sdk/server"
ethlog "github.com/ethereum/go-ethereum/log"
"github.com/rs/zerolog"
"github.com/tendermint/tendermint/types/time"
)
func BenchmarkHandler_Log(b *testing.B) {
logger := &server.ZeroLogWrapper{
Logger: zerolog.New(io.Discard).Level(zerolog.DebugLevel).With().Timestamp().Logger(),
}
h := NewHandler(logger)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
h.Log(&ethlog.Record{
Time: time.Now().UTC(),
Lvl: ethlog.LvlCrit,
Msg: "critical error",
KeyNames: ethlog.RecordKeyNames{
Time: timeKey,
Msg: msgKey,
Lvl: lvlKey,
Ctx: ctxKey,
},
})
}
}

View File

@ -1,88 +0,0 @@
package log
import (
"github.com/rs/zerolog"
"github.com/cosmos/cosmos-sdk/server"
ethlog "github.com/ethereum/go-ethereum/log"
tmlog "github.com/tendermint/tendermint/libs/log"
)
var _ ethlog.Handler = &Handler{}
// Logger wraps the zero log Wrapper and extends it to support the ethereum logger interface.
type Handler struct {
*server.ZeroLogWrapper
}
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
}
return &Handler{
ZeroLogWrapper: zerologger,
}
}
// Log implements the go-ethereum Logger Handler interface
func (h *Handler) Log(r *ethlog.Record) error {
lvl := EthLogLvlToZerolog(r.Lvl)
h.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
}
return level
}
func getLogFields(keyVals ...interface{}) map[string]interface{} {
if len(keyVals)%2 != 0 {
return nil
}
fields := make(map[string]interface{})
for i := 0; i < len(keyVals); i += 2 {
fields[keyVals[i].(string)] = keyVals[i+1]
}
return fields
}
// var ethermintLogger *tmlog.Logger = nil
// func NewHandler(logger tmlog.Logger) ethlog.Handler {
// ethermintLogger = &logger
// return ethlog.FuncHandler(func(r *ethlog.Record) error {
// (*ethermintLogger).Debug(fmt.Sprintf("[EVM] %v", r))
// return nil
// })
// }

View File

@ -1,62 +0,0 @@
package log
import (
"bytes"
"testing"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/types/time"
"github.com/cosmos/cosmos-sdk/server"
ethlog "github.com/ethereum/go-ethereum/log"
)
const (
timeKey = "t"
lvlKey = "lvl"
msgKey = "msg"
ctxKey = "ctx"
)
func TestLog(t *testing.T) {
out := &bytes.Buffer{}
logger := &server.ZeroLogWrapper{
Logger: zerolog.New(out).Level(zerolog.DebugLevel).With().Timestamp().Logger(),
}
h := NewHandler(logger)
err := h.Log(&ethlog.Record{
Time: time.Now().UTC(),
Lvl: ethlog.LvlCrit,
Msg: "critical error",
KeyNames: ethlog.RecordKeyNames{
Time: timeKey,
Msg: msgKey,
Lvl: lvlKey,
Ctx: ctxKey,
},
})
require.NoError(t, err)
require.Contains(t, string(out.Bytes()), "\"message\":\"critical error\"")
require.Contains(t, string(out.Bytes()), "\"level\":\"fatal\"")
}
func TestOverrideRootLogger(t *testing.T) {
out := &bytes.Buffer{}
logger := &server.ZeroLogWrapper{
Logger: zerolog.New(out).Level(zerolog.DebugLevel).With().Timestamp().Logger(),
}
h := NewHandler(logger)
ethlog.Root().SetHandler(h)
ethlog.Root().Info("some info")
require.Contains(t, string(out.Bytes()), "\"message\":\"some info\"")
require.Contains(t, string(out.Bytes()), "\"level\":\"info\"")
}