mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
cmd,log: using DiscardHandler in go std lib
This commit is contained in:
parent
d39af344dc
commit
1535716bce
4 changed files with 5 additions and 26 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/cmd/devp2p/internal/v4test"
|
"github.com/ethereum/go-ethereum/cmd/devp2p/internal/v4test"
|
||||||
|
|
@ -86,7 +87,7 @@ func runTests(ctx *cli.Context, tests []utesting.Test) error {
|
||||||
}
|
}
|
||||||
// Disable logging unless explicitly enabled.
|
// Disable logging unless explicitly enabled.
|
||||||
if !ctx.IsSet("verbosity") && !ctx.IsSet("vmodule") {
|
if !ctx.IsSet("verbosity") && !ctx.IsSet("vmodule") {
|
||||||
log.SetDefault(log.NewLogger(log.DiscardHandler()))
|
log.SetDefault(log.NewLogger(slog.DiscardHandler))
|
||||||
}
|
}
|
||||||
// Run the tests.
|
// Run the tests.
|
||||||
var run = utesting.RunTests
|
var run = utesting.RunTests
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"embed"
|
"embed"
|
||||||
"errors"
|
"errors"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/history"
|
"github.com/ethereum/go-ethereum/core/history"
|
||||||
|
|
@ -240,7 +241,7 @@ func runTestCmd(ctx *cli.Context) error {
|
||||||
|
|
||||||
// Disable logging unless explicitly enabled.
|
// Disable logging unless explicitly enabled.
|
||||||
if !ctx.IsSet("verbosity") && !ctx.IsSet("vmodule") {
|
if !ctx.IsSet("verbosity") && !ctx.IsSet("vmodule") {
|
||||||
log.SetDefault(log.NewLogger(log.DiscardHandler()))
|
log.SetDefault(log.NewLogger(slog.DiscardHandler))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the tests.
|
// Run the tests.
|
||||||
|
|
|
||||||
|
|
@ -13,29 +13,6 @@ import (
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
)
|
)
|
||||||
|
|
||||||
type discardHandler struct{}
|
|
||||||
|
|
||||||
// DiscardHandler returns a no-op handler
|
|
||||||
func DiscardHandler() slog.Handler {
|
|
||||||
return &discardHandler{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *discardHandler) Handle(_ context.Context, r slog.Record) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *discardHandler) Enabled(_ context.Context, level slog.Level) bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *discardHandler) WithGroup(name string) slog.Handler {
|
|
||||||
panic("not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *discardHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
|
|
||||||
return &discardHandler{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type TerminalHandler struct {
|
type TerminalHandler struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
wr io.Writer
|
wr io.Writer
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
root = &logger{slog.New(DiscardHandler())}
|
root = &logger{slog.New(slog.DiscardHandler)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDefault sets the default global logger
|
// SetDefault sets the default global logger
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue