fix: replace logger

Signed-off-by: Isma <71719097+Doozers@users.noreply.github.com>
This commit is contained in:
Isma 2023-12-22 15:21:21 +01:00 committed by mortimr
parent 99b3384834
commit 58a958e374
4 changed files with 8 additions and 80 deletions

View file

@ -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()
})
}

View file

@ -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,

View file

@ -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
}

View file

@ -1,5 +1,7 @@
#! /bin/bash
go get github.com/sirupsen/logrus
for d in plugins/*/ ; do
CWD=$(pwd)
echo "fetch dependencies $d"