From 58a958e3742f9d1a308a63fb49ff46874721a5fa Mon Sep 17 00:00:00 2001 From: Isma <71719097+Doozers@users.noreply.github.com> Date: Fri, 22 Dec 2023 15:21:21 +0100 Subject: [PATCH] fix: replace logger Signed-off-by: Isma <71719097+Doozers@users.noreply.github.com> --- log/format.pgeth.go | 71 ---------------------------------------- pgeth/engine.go | 10 ++---- pgeth/toolkit/toolkit.go | 5 +-- plugins/build.sh | 2 ++ 4 files changed, 8 insertions(+), 80 deletions(-) delete mode 100644 log/format.pgeth.go diff --git a/log/format.pgeth.go b/log/format.pgeth.go deleted file mode 100644 index d6968b69f8..0000000000 --- a/log/format.pgeth.go +++ /dev/null @@ -1,71 +0,0 @@ -package log - -import ( - "bytes" - "fmt" - "strings" - "unicode/utf8" -) - -func PgethFormat(usecolor bool) Format { - return FormatFunc(func(r *Record) []byte { - var color = 0 - if usecolor { - switch r.Lvl { - case LvlCrit: - color = 35 - case LvlError: - color = 31 - case LvlWarn: - color = 33 - case LvlInfo: - color = 34 - case LvlDebug: - color = 36 - case LvlTrace: - color = 34 - } - } - - b := &bytes.Buffer{} - lvl := r.Lvl.AlignedString() - if lvl == "INFO " { - lvl = "PLUG " - } - if locationEnabled.Load() { - // Log origin printing was requested, format the location path and line number - location := fmt.Sprintf("%+v", r.Call) - for _, prefix := range locationTrims { - location = strings.TrimPrefix(location, prefix) - } - // Maintain the maximum location length for fancyer alignment - align := int(locationLength.Load()) - if align < len(location) { - align = len(location) - locationLength.Store(uint32(align)) - } - padding := strings.Repeat(" ", align-len(location)) - - // Assemble and print the log heading - if color > 0 { - fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s|%s]%s %s ", color, lvl, r.Time.Format(termTimeFormat), location, padding, r.Msg) - } else { - fmt.Fprintf(b, "%s[%s|%s]%s %s ", lvl, r.Time.Format(termTimeFormat), location, padding, r.Msg) - } - } else { - if color > 0 { - fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %s ", color, lvl, r.Time.Format(termTimeFormat), r.Msg) - } else { - fmt.Fprintf(b, "%s[%s] %s ", lvl, r.Time.Format(termTimeFormat), r.Msg) - } - } - // try to justify the log output for short messages - length := utf8.RuneCountInString(r.Msg) - if len(r.Ctx) > 0 && length < termMsgJust { - b.Write(bytes.Repeat([]byte{' '}, termMsgJust-length)) - } - // print the keys logfmt style - logfmt(b, r.Ctx, color, true) - return b.Bytes() - }) -} diff --git a/pgeth/engine.go b/pgeth/engine.go index 67a99d998a..8425371d89 100644 --- a/pgeth/engine.go +++ b/pgeth/engine.go @@ -6,11 +6,11 @@ import ( "os" "runtime/debug" - "github.com/mattn/go-colorable" "gopkg.in/yaml.v2" + log "github.com/sirupsen/logrus" + "github.com/ethereum/go-ethereum/internal/ethapi" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/pgeth/toolkit" pgeth_monitoring "github.com/ethereum/go-ethereum/plugins/pgeth-monitoring" @@ -35,16 +35,12 @@ type PluginEngineConfig struct { type PluginEngine struct { node *node.Node backend ethapi.Backend - logger log.Logger + logger *log.Logger } func NewEngine(cfg *PluginEngineConfig) *PluginEngine { logger := log.New() - var ostream log.Handler - output := colorable.NewColorableStdout() - ostream = log.StreamHandler(output, log.PgethFormat(true)) - logger.SetHandler(ostream) return &PluginEngine{ node: cfg.Node, backend: cfg.Backend, diff --git a/pgeth/toolkit/toolkit.go b/pgeth/toolkit/toolkit.go index 549ffb3075..9acb3ae205 100644 --- a/pgeth/toolkit/toolkit.go +++ b/pgeth/toolkit/toolkit.go @@ -1,13 +1,14 @@ package toolkit import ( + log "github.com/sirupsen/logrus" + "github.com/ethereum/go-ethereum/internal/ethapi" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" ) type PluginToolkit struct { Node *node.Node Backend ethapi.Backend - Logger log.Logger + Logger *log.Logger } diff --git a/plugins/build.sh b/plugins/build.sh index c782e4e4a4..6d6ab950d5 100755 --- a/plugins/build.sh +++ b/plugins/build.sh @@ -1,5 +1,7 @@ #! /bin/bash +go get github.com/sirupsen/logrus + for d in plugins/*/ ; do CWD=$(pwd) echo "fetch dependencies $d"