mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
log, debug: make terminal handler public, change how to reset fieldpadding map
This commit is contained in:
parent
8a9e7d5f0b
commit
b61bbbfd0f
22 changed files with 64 additions and 52 deletions
|
|
@ -232,7 +232,7 @@ func abigen(c *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true)))
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ func main() {
|
||||||
)
|
)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
glogger := log.NewGlogHandler(log.TerminalHandler(os.Stderr, false))
|
glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false))
|
||||||
glogger.Verbosity(slog.Level(*verbosity))
|
glogger.Verbosity(slog.Level(*verbosity))
|
||||||
glogger.Vmodule(*vmodule)
|
glogger.Vmodule(*vmodule)
|
||||||
log.SetDefault(log.NewLogger(glogger))
|
log.SetDefault(log.NewLogger(glogger))
|
||||||
|
|
|
||||||
|
|
@ -493,7 +493,7 @@ func initialize(c *cli.Context) error {
|
||||||
if usecolor {
|
if usecolor {
|
||||||
output = colorable.NewColorable(logOutput)
|
output = colorable.NewColorable(logOutput)
|
||||||
}
|
}
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(output, slog.Level(c.Int(logLevelFlag.Name)), usecolor)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(output, slog.Level(c.Int(logLevelFlag.Name)), usecolor)))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,7 @@ func (i *bbInput) sealClique(block *types.Block) (*types.Block, error) {
|
||||||
// BuildBlock constructs a block from the given inputs.
|
// BuildBlock constructs a block from the given inputs.
|
||||||
func BuildBlock(ctx *cli.Context) error {
|
func BuildBlock(ctx *cli.Context) error {
|
||||||
// Configure the go-ethereum logger
|
// Configure the go-ethereum logger
|
||||||
glogger := log.NewGlogHandler(log.TerminalHandler(os.Stderr, false))
|
glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false))
|
||||||
glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name)))
|
glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name)))
|
||||||
log.SetDefault(log.NewLogger(glogger))
|
log.SetDefault(log.NewLogger(glogger))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ func (r *result) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
func Transaction(ctx *cli.Context) error {
|
func Transaction(ctx *cli.Context) error {
|
||||||
// Configure the go-ethereum logger
|
// Configure the go-ethereum logger
|
||||||
glogger := log.NewGlogHandler(log.TerminalHandler(os.Stderr, false))
|
glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false))
|
||||||
glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name)))
|
glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name)))
|
||||||
log.SetDefault(log.NewLogger(glogger))
|
log.SetDefault(log.NewLogger(glogger))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ type input struct {
|
||||||
|
|
||||||
func Transition(ctx *cli.Context) error {
|
func Transition(ctx *cli.Context) error {
|
||||||
// Configure the go-ethereum logger
|
// Configure the go-ethereum logger
|
||||||
glogger := log.NewGlogHandler(log.TerminalHandler(os.Stderr, false))
|
glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false))
|
||||||
glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name)))
|
glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name)))
|
||||||
log.SetDefault(log.NewLogger(glogger))
|
log.SetDefault(log.NewLogger(glogger))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ var websiteTmpl string
|
||||||
func main() {
|
func main() {
|
||||||
// Parse the flags and set up the logger to print everything requested
|
// Parse the flags and set up the logger to print everything requested
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, slog.Level(*logFlag), true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, slog.Level(*logFlag), true)))
|
||||||
|
|
||||||
// Construct the payout tiers
|
// Construct the payout tiers
|
||||||
amounts := make([]string, *tiersFlag)
|
amounts := make([]string, *tiersFlag)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -51,10 +50,8 @@ func (c customQuotedStringer) String() string {
|
||||||
// logTest is an entry point which spits out some logs. This is used by testing
|
// logTest is an entry point which spits out some logs. This is used by testing
|
||||||
// to verify expected outputs
|
// to verify expected outputs
|
||||||
func logTest(ctx *cli.Context) error {
|
func logTest(ctx *cli.Context) error {
|
||||||
// if log is set to output terminal format, reset root logger to clear field padding map
|
// clear field padding map
|
||||||
if !ctx.IsSet(debug.LogFormatFlag.Name) || ctx.String(debug.LogFormatFlag.Name) == "terminal" {
|
debug.ResetLogging()
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandler(os.Stdout, false)))
|
|
||||||
}
|
|
||||||
|
|
||||||
{ // big.Int
|
{ // big.Int
|
||||||
ba, _ := new(big.Int).SetString("111222333444555678999", 10) // "111,222,333,444,555,678,999"
|
ba, _ := new(big.Int).SetString("111222333444555678999", 10) // "111,222,333,444,555,678,999"
|
||||||
|
|
|
||||||
|
|
@ -601,7 +601,7 @@ func testGenerateWithExtraAccounts(t *testing.T, scheme string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func enableLogging() {
|
func enableLogging() {
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that snapshot generation when an extra account with storage exists in the snap state.
|
// Tests that snapshot generation when an extra account with storage exists in the snap state.
|
||||||
|
|
|
||||||
|
|
@ -319,7 +319,7 @@ func verifyPoolInternals(t *testing.T, pool *BlobPool) {
|
||||||
// - 3. All transactions after a nonce gap must be dropped
|
// - 3. All transactions after a nonce gap must be dropped
|
||||||
// - 4. All transactions after an underpriced one (including it) must be dropped
|
// - 4. All transactions after an underpriced one (including it) must be dropped
|
||||||
func TestOpenDrops(t *testing.T) {
|
func TestOpenDrops(t *testing.T) {
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
||||||
|
|
||||||
// Create a temporary folder for the persistent backend
|
// Create a temporary folder for the persistent backend
|
||||||
storage, _ := os.MkdirTemp("", "blobpool-")
|
storage, _ := os.MkdirTemp("", "blobpool-")
|
||||||
|
|
@ -600,7 +600,7 @@ func TestOpenDrops(t *testing.T) {
|
||||||
// - 2. Eviction thresholds are calculated correctly for the sequences
|
// - 2. Eviction thresholds are calculated correctly for the sequences
|
||||||
// - 3. Balance usage of an account is totals across all transactions
|
// - 3. Balance usage of an account is totals across all transactions
|
||||||
func TestOpenIndex(t *testing.T) {
|
func TestOpenIndex(t *testing.T) {
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
||||||
|
|
||||||
// Create a temporary folder for the persistent backend
|
// Create a temporary folder for the persistent backend
|
||||||
storage, _ := os.MkdirTemp("", "blobpool-")
|
storage, _ := os.MkdirTemp("", "blobpool-")
|
||||||
|
|
@ -689,7 +689,7 @@ func TestOpenIndex(t *testing.T) {
|
||||||
// Tests that after indexing all the loaded transactions from disk, a price heap
|
// Tests that after indexing all the loaded transactions from disk, a price heap
|
||||||
// is correctly constructed based on the head basefee and blobfee.
|
// is correctly constructed based on the head basefee and blobfee.
|
||||||
func TestOpenHeap(t *testing.T) {
|
func TestOpenHeap(t *testing.T) {
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
||||||
|
|
||||||
// Create a temporary folder for the persistent backend
|
// Create a temporary folder for the persistent backend
|
||||||
storage, _ := os.MkdirTemp("", "blobpool-")
|
storage, _ := os.MkdirTemp("", "blobpool-")
|
||||||
|
|
@ -776,7 +776,7 @@ func TestOpenHeap(t *testing.T) {
|
||||||
// Tests that after the pool's previous state is loaded back, any transactions
|
// Tests that after the pool's previous state is loaded back, any transactions
|
||||||
// over the new storage cap will get dropped.
|
// over the new storage cap will get dropped.
|
||||||
func TestOpenCap(t *testing.T) {
|
func TestOpenCap(t *testing.T) {
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
||||||
|
|
||||||
// Create a temporary folder for the persistent backend
|
// Create a temporary folder for the persistent backend
|
||||||
storage, _ := os.MkdirTemp("", "blobpool-")
|
storage, _ := os.MkdirTemp("", "blobpool-")
|
||||||
|
|
@ -868,7 +868,7 @@ func TestOpenCap(t *testing.T) {
|
||||||
// specific to the blob pool. It does not do an exhaustive transaction validity
|
// specific to the blob pool. It does not do an exhaustive transaction validity
|
||||||
// check.
|
// check.
|
||||||
func TestAdd(t *testing.T) {
|
func TestAdd(t *testing.T) {
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
||||||
|
|
||||||
// seed is a helper tumpe to seed an initial state db and pool
|
// seed is a helper tumpe to seed an initial state db and pool
|
||||||
type seed struct {
|
type seed struct {
|
||||||
|
|
|
||||||
|
|
@ -1562,7 +1562,7 @@ func TestBlockToPayloadWithBlobs(t *testing.T) {
|
||||||
|
|
||||||
// This checks that beaconRoot is applied to the state from the engine API.
|
// This checks that beaconRoot is applied to the state from the engine API.
|
||||||
func TestParentBeaconBlockRoot(t *testing.T) {
|
func TestParentBeaconBlockRoot(t *testing.T) {
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(colorable.NewColorableStderr(), log.LevelTrace, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(colorable.NewColorableStderr(), log.LevelTrace, true)))
|
||||||
|
|
||||||
genesis, blocks := generateMergeChain(10, true)
|
genesis, blocks := generateMergeChain(10, true)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ var (
|
||||||
Hidden: true,
|
Hidden: true,
|
||||||
Category: flags.LoggingCategory,
|
Category: flags.LoggingCategory,
|
||||||
}
|
}
|
||||||
LogFormatFlag = &cli.StringFlag{
|
logFormatFlag = &cli.StringFlag{
|
||||||
Name: "log.format",
|
Name: "log.format",
|
||||||
Usage: "Log format to use (json|logfmt|terminal)",
|
Usage: "Log format to use (json|logfmt|terminal)",
|
||||||
Category: flags.LoggingCategory,
|
Category: flags.LoggingCategory,
|
||||||
|
|
@ -151,7 +151,7 @@ var Flags = []cli.Flag{
|
||||||
logVmoduleFlag,
|
logVmoduleFlag,
|
||||||
vmoduleFlag,
|
vmoduleFlag,
|
||||||
logjsonFlag,
|
logjsonFlag,
|
||||||
LogFormatFlag,
|
logFormatFlag,
|
||||||
logFileFlag,
|
logFileFlag,
|
||||||
logRotateFlag,
|
logRotateFlag,
|
||||||
logMaxSizeMBsFlag,
|
logMaxSizeMBsFlag,
|
||||||
|
|
@ -168,16 +168,24 @@ var Flags = []cli.Flag{
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
glogger *log.GlogHandler
|
glogger *log.GlogHandler
|
||||||
logOutputF *os.File
|
logOutputF *os.File
|
||||||
|
defaultTerminalHandler *log.TerminalHandler
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
glogger = log.NewGlogHandler(log.TerminalHandler(os.Stderr, false))
|
defaultTerminalHandler = log.NewTerminalHandler(os.Stderr, false)
|
||||||
|
glogger = log.NewGlogHandler(defaultTerminalHandler)
|
||||||
glogger.Verbosity(log.LvlInfo)
|
glogger.Verbosity(log.LvlInfo)
|
||||||
log.SetDefault(log.NewLogger(glogger))
|
log.SetDefault(log.NewLogger(glogger))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ResetLogging() {
|
||||||
|
if defaultTerminalHandler != nil {
|
||||||
|
defaultTerminalHandler.ResetFieldPadding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Setup initializes profiling and logging based on the CLI flags.
|
// Setup initializes profiling and logging based on the CLI flags.
|
||||||
// It should be called as early as possible in the program.
|
// It should be called as early as possible in the program.
|
||||||
func Setup(ctx *cli.Context) error {
|
func Setup(ctx *cli.Context) error {
|
||||||
|
|
@ -186,7 +194,7 @@ func Setup(ctx *cli.Context) error {
|
||||||
fileOutput io.Writer
|
fileOutput io.Writer
|
||||||
terminalOutput = io.Writer(os.Stderr)
|
terminalOutput = io.Writer(os.Stderr)
|
||||||
output io.Writer
|
output io.Writer
|
||||||
logFmtFlag = ctx.String(LogFormatFlag.Name)
|
logFmtFlag = ctx.String(logFormatFlag.Name)
|
||||||
)
|
)
|
||||||
var (
|
var (
|
||||||
logFile = ctx.String(logFileFlag.Name)
|
logFile = ctx.String(logFileFlag.Name)
|
||||||
|
|
@ -249,10 +257,10 @@ func Setup(ctx *cli.Context) error {
|
||||||
output = terminalOutput
|
output = terminalOutput
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handler = log.TerminalHandler(output, useColor)
|
handler = log.NewTerminalHandler(output, useColor)
|
||||||
default:
|
default:
|
||||||
// Unknown log format specified
|
// Unknown log format specified
|
||||||
return fmt.Errorf("unknown log format: %v", ctx.String(LogFormatFlag.Name))
|
return fmt.Errorf("unknown log format: %v", ctx.String(logFormatFlag.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
glogger = log.NewGlogHandler(handler)
|
glogger = log.NewGlogHandler(handler)
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,7 @@ func (l *logger) New(ctx ...interface{}) log.Logger {
|
||||||
return l.With(ctx...)
|
return l.With(ctx...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// terminalFormat formats a message similarly to the TerminalHandler in the log package.
|
// terminalFormat formats a message similarly to the NewTerminalHandler in the log package.
|
||||||
// The difference is that terminalFormat does not escape messages/attributes and does not pad attributes.
|
// The difference is that terminalFormat does not escape messages/attributes and does not pad attributes.
|
||||||
func (h *bufHandler) terminalFormat(r slog.Record) string {
|
func (h *bufHandler) terminalFormat(r slog.Record) string {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ var (
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.Level(*loglevel), true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.Level(*loglevel), true)))
|
||||||
// register the Delivery service which will run as a devp2p
|
// register the Delivery service which will run as a devp2p
|
||||||
// protocol when using the exec adapter
|
// protocol when using the exec adapter
|
||||||
adapters.RegisterLifecycles(services)
|
adapters.RegisterLifecycles(services)
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ type TerminalStringer interface {
|
||||||
TerminalString() string
|
TerminalString() string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *terminalHandler) TerminalFormat(r slog.Record, usecolor bool) []byte {
|
func (h *TerminalHandler) TerminalFormat(r slog.Record, usecolor bool) []byte {
|
||||||
msg := escapeMessage(r.Message)
|
msg := escapeMessage(r.Message)
|
||||||
var color = 0
|
var color = 0
|
||||||
if usecolor {
|
if usecolor {
|
||||||
|
|
@ -82,7 +82,7 @@ func (h *terminalHandler) TerminalFormat(r slog.Record, usecolor bool) []byte {
|
||||||
return b.Bytes()
|
return b.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *terminalHandler) logfmt(buf *bytes.Buffer, r slog.Record, color int) {
|
func (h *TerminalHandler) logfmt(buf *bytes.Buffer, r slog.Record, color int) {
|
||||||
attrs := []slog.Attr{}
|
attrs := []slog.Attr{}
|
||||||
r.Attrs(func(attr slog.Attr) bool {
|
r.Attrs(func(attr slog.Attr) bool {
|
||||||
attrs = append(attrs, attr)
|
attrs = append(attrs, attr)
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ func (h *discardHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
|
||||||
return &discardHandler{}
|
return &discardHandler{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type terminalHandler struct {
|
type TerminalHandler struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
wr io.Writer
|
wr io.Writer
|
||||||
lvl slog.Level
|
lvl slog.Level
|
||||||
|
|
@ -83,7 +83,7 @@ type terminalHandler struct {
|
||||||
fieldPadding map[string]int
|
fieldPadding map[string]int
|
||||||
}
|
}
|
||||||
|
|
||||||
// TerminalHandler returns a handler which formats log records at all levels optimized for human readability on
|
// NewTerminalHandler returns a handler which formats log records at all levels optimized for human readability on
|
||||||
// a terminal with color-coded level output and terser human friendly timestamp.
|
// a terminal with color-coded level output and terser human friendly timestamp.
|
||||||
// This format should only be used for interactive programs or while developing.
|
// This format should only be used for interactive programs or while developing.
|
||||||
//
|
//
|
||||||
|
|
@ -92,14 +92,14 @@ type terminalHandler struct {
|
||||||
// Example:
|
// Example:
|
||||||
//
|
//
|
||||||
// [DBUG] [May 16 20:58:45] remove route ns=haproxy addr=127.0.0.1:50002
|
// [DBUG] [May 16 20:58:45] remove route ns=haproxy addr=127.0.0.1:50002
|
||||||
func TerminalHandler(wr io.Writer, useColor bool) slog.Handler {
|
func NewTerminalHandler(wr io.Writer, useColor bool) *TerminalHandler {
|
||||||
return TerminalHandlerWithLevel(wr, levelMaxVerbosity, useColor)
|
return NewTerminalHandlerWithLevel(wr, levelMaxVerbosity, useColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TerminalHandlerWithLevel returns the same handler as TerminalHandler but only outputs
|
// NewTerminalHandlerWithLevel returns the same handler as NewTerminalHandler but only outputs
|
||||||
// records which are less than or equal to the specified verbosity level.
|
// records which are less than or equal to the specified verbosity level.
|
||||||
func TerminalHandlerWithLevel(wr io.Writer, lvl slog.Level, useColor bool) slog.Handler {
|
func NewTerminalHandlerWithLevel(wr io.Writer, lvl slog.Level, useColor bool) *TerminalHandler {
|
||||||
return &terminalHandler{
|
return &TerminalHandler{
|
||||||
sync.Mutex{},
|
sync.Mutex{},
|
||||||
wr,
|
wr,
|
||||||
lvl,
|
lvl,
|
||||||
|
|
@ -109,23 +109,23 @@ func TerminalHandlerWithLevel(wr io.Writer, lvl slog.Level, useColor bool) slog.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *terminalHandler) Handle(_ context.Context, r slog.Record) error {
|
func (h *TerminalHandler) Handle(_ context.Context, r slog.Record) error {
|
||||||
h.mu.Lock()
|
h.mu.Lock()
|
||||||
defer h.mu.Unlock()
|
defer h.mu.Unlock()
|
||||||
h.wr.Write(h.TerminalFormat(r, h.useColor))
|
h.wr.Write(h.TerminalFormat(r, h.useColor))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *terminalHandler) Enabled(_ context.Context, level slog.Level) bool {
|
func (h *TerminalHandler) Enabled(_ context.Context, level slog.Level) bool {
|
||||||
return level >= h.lvl
|
return level >= h.lvl
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *terminalHandler) WithGroup(name string) slog.Handler {
|
func (h *TerminalHandler) WithGroup(name string) slog.Handler {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *terminalHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
|
func (h *TerminalHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
|
||||||
return &terminalHandler{
|
return &TerminalHandler{
|
||||||
sync.Mutex{},
|
sync.Mutex{},
|
||||||
h.wr,
|
h.wr,
|
||||||
h.lvl,
|
h.lvl,
|
||||||
|
|
@ -135,6 +135,13 @@ func (h *terminalHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResetFieldPadding zeroes the field-padding for all attribute pairs.
|
||||||
|
func (t *TerminalHandler) ResetFieldPadding() {
|
||||||
|
t.mu.Lock()
|
||||||
|
t.fieldPadding = make(map[string]int)
|
||||||
|
t.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
type leveler struct{ minLevel slog.Level }
|
type leveler struct{ minLevel slog.Level }
|
||||||
|
|
||||||
func (l *leveler) Level() slog.Level {
|
func (l *leveler) Level() slog.Level {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
// TestLoggingWithVmodule checks that vmodule works.
|
// TestLoggingWithVmodule checks that vmodule works.
|
||||||
func TestLoggingWithVmodule(t *testing.T) {
|
func TestLoggingWithVmodule(t *testing.T) {
|
||||||
out := new(bytes.Buffer)
|
out := new(bytes.Buffer)
|
||||||
glog := NewGlogHandler(TerminalHandlerWithLevel(out, LevelTrace, false))
|
glog := NewGlogHandler(NewTerminalHandlerWithLevel(out, LevelTrace, false))
|
||||||
glog.Verbosity(LevelCrit)
|
glog.Verbosity(LevelCrit)
|
||||||
logger := NewLogger(glog)
|
logger := NewLogger(glog)
|
||||||
logger.Warn("This should not be seen", "ignored", "true")
|
logger.Warn("This should not be seen", "ignored", "true")
|
||||||
|
|
@ -30,7 +30,7 @@ func TestLoggingWithVmodule(t *testing.T) {
|
||||||
|
|
||||||
func TestTerminalHandlerWithAttrs(t *testing.T) {
|
func TestTerminalHandlerWithAttrs(t *testing.T) {
|
||||||
out := new(bytes.Buffer)
|
out := new(bytes.Buffer)
|
||||||
glog := NewGlogHandler(TerminalHandlerWithLevel(out, LevelTrace, false).WithAttrs([]slog.Attr{slog.String("baz", "bat")}))
|
glog := NewGlogHandler(NewTerminalHandlerWithLevel(out, LevelTrace, false).WithAttrs([]slog.Attr{slog.String("baz", "bat")}))
|
||||||
glog.Verbosity(LevelTrace)
|
glog.Verbosity(LevelTrace)
|
||||||
logger := NewLogger(glog)
|
logger := NewLogger(glog)
|
||||||
logger.Trace("a message", "foo", "bar")
|
logger.Trace("a message", "foo", "bar")
|
||||||
|
|
@ -45,7 +45,7 @@ func TestTerminalHandlerWithAttrs(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkTraceLogging(b *testing.B) {
|
func BenchmarkTraceLogging(b *testing.B) {
|
||||||
SetDefault(NewLogger(TerminalHandler(os.Stderr, true)))
|
SetDefault(NewLogger(NewTerminalHandler(os.Stderr, true)))
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
Trace("a message", "v", i)
|
Trace("a message", "v", i)
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true)))
|
||||||
fdlimit.Raise(2048)
|
fdlimit.Raise(2048)
|
||||||
|
|
||||||
// Generate a batch of accounts to seal and fund with
|
// Generate a batch of accounts to seal and fund with
|
||||||
|
|
|
||||||
|
|
@ -403,7 +403,7 @@ func initLogging() {
|
||||||
verbosity = log.FromLegacyLevel(int(conf.Node.LogVerbosity))
|
verbosity = log.FromLegacyLevel(int(conf.Node.LogVerbosity))
|
||||||
}
|
}
|
||||||
// Reinitialize the logger
|
// Reinitialize the logger
|
||||||
innerHandler = log.TerminalHandler(writer, true)
|
innerHandler = log.NewTerminalHandler(writer, true)
|
||||||
glogger = log.NewGlogHandler(innerHandler)
|
glogger = log.NewGlogHandler(innerHandler)
|
||||||
glogger.Verbosity(verbosity)
|
glogger.Verbosity(verbosity)
|
||||||
log.SetDefault(log.NewLogger(glogger))
|
log.SetDefault(log.NewLogger(glogger))
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// set the log level to Trace
|
// set the log level to Trace
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, false)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, false)))
|
||||||
|
|
||||||
// register a single ping-pong service
|
// register a single ping-pong service
|
||||||
services := map[string]adapters.LifecycleConstructor{
|
services := map[string]adapters.LifecycleConstructor{
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ func TestMain(m *testing.M) {
|
||||||
loglevel := flag.Int("loglevel", 2, "verbosity of logs")
|
loglevel := flag.Int("loglevel", 2, "verbosity of logs")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.Level(*loglevel), true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.Level(*loglevel), true)))
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ func TestFileStorage(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func TestEnd2End(t *testing.T) {
|
func TestEnd2End(t *testing.T) {
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.LevelInfo, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.LevelInfo, true)))
|
||||||
|
|
||||||
d := t.TempDir()
|
d := t.TempDir()
|
||||||
|
|
||||||
|
|
@ -112,7 +112,7 @@ func TestEnd2End(t *testing.T) {
|
||||||
func TestSwappedKeys(t *testing.T) {
|
func TestSwappedKeys(t *testing.T) {
|
||||||
// It should not be possible to swap the keys/values, so that
|
// It should not be possible to swap the keys/values, so that
|
||||||
// K1:V1, K2:V2 can be swapped into K1:V2, K2:V1
|
// K1:V1, K2:V2 can be swapped into K1:V2, K2:V1
|
||||||
log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.LevelInfo, true)))
|
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.LevelInfo, true)))
|
||||||
|
|
||||||
d := t.TempDir()
|
d := t.TempDir()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue