mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
fix: replace logger
Signed-off-by: Isma <71719097+Doozers@users.noreply.github.com>
This commit is contained in:
parent
99b3384834
commit
58a958e374
4 changed files with 8 additions and 80 deletions
|
|
@ -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()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
@ -6,11 +6,11 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
|
||||||
"github.com/mattn/go-colorable"
|
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/pgeth/toolkit"
|
"github.com/ethereum/go-ethereum/pgeth/toolkit"
|
||||||
pgeth_monitoring "github.com/ethereum/go-ethereum/plugins/pgeth-monitoring"
|
pgeth_monitoring "github.com/ethereum/go-ethereum/plugins/pgeth-monitoring"
|
||||||
|
|
@ -35,16 +35,12 @@ type PluginEngineConfig struct {
|
||||||
type PluginEngine struct {
|
type PluginEngine struct {
|
||||||
node *node.Node
|
node *node.Node
|
||||||
backend ethapi.Backend
|
backend ethapi.Backend
|
||||||
logger log.Logger
|
logger *log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEngine(cfg *PluginEngineConfig) *PluginEngine {
|
func NewEngine(cfg *PluginEngineConfig) *PluginEngine {
|
||||||
logger := log.New()
|
logger := log.New()
|
||||||
|
|
||||||
var ostream log.Handler
|
|
||||||
output := colorable.NewColorableStdout()
|
|
||||||
ostream = log.StreamHandler(output, log.PgethFormat(true))
|
|
||||||
logger.SetHandler(ostream)
|
|
||||||
return &PluginEngine{
|
return &PluginEngine{
|
||||||
node: cfg.Node,
|
node: cfg.Node,
|
||||||
backend: cfg.Backend,
|
backend: cfg.Backend,
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
package toolkit
|
package toolkit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PluginToolkit struct {
|
type PluginToolkit struct {
|
||||||
Node *node.Node
|
Node *node.Node
|
||||||
Backend ethapi.Backend
|
Backend ethapi.Backend
|
||||||
Logger log.Logger
|
Logger *log.Logger
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
|
go get github.com/sirupsen/logrus
|
||||||
|
|
||||||
for d in plugins/*/ ; do
|
for d in plugins/*/ ; do
|
||||||
CWD=$(pwd)
|
CWD=$(pwd)
|
||||||
echo "fetch dependencies $d"
|
echo "fetch dependencies $d"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue