mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
commit
4967a17566
3 changed files with 6 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"
|
||||
"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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue