-
Notifications
You must be signed in to change notification settings - Fork 21.6k
log: using DiscardHandler in golang std lib #32647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cuiweixie
wants to merge
1
commit into
ethereum:master
Choose a base branch
from
cuiweixie:DiscardHandler
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
|
@fjl can you help to review this pr? |
Member
|
I don't think this change is essential, but if you really want to change it, please adopt the diff below. diff --git a/cmd/devp2p/runtest.go b/cmd/devp2p/runtest.go
index c40a4b8a01..90ab2f2530 100644
--- a/cmd/devp2p/runtest.go
+++ b/cmd/devp2p/runtest.go
@@ -17,6 +17,7 @@
package main
import (
+ "log/slog"
"os"
"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.
if !ctx.IsSet("verbosity") && !ctx.IsSet("vmodule") {
- log.SetDefault(log.NewLogger(log.DiscardHandler()))
+ log.SetDefault(log.NewLogger(slog.DiscardHandler))
}
// Run the tests.
var run = utesting.RunTests
diff --git a/cmd/workload/testsuite.go b/cmd/workload/testsuite.go
index 25dc17a49e..3a1796107d 100644
--- a/cmd/workload/testsuite.go
+++ b/cmd/workload/testsuite.go
@@ -20,6 +20,7 @@ import (
"embed"
"errors"
"io/fs"
+ "log/slog"
"os"
"github.com/ethereum/go-ethereum/core/history"
@@ -240,7 +241,7 @@ func runTestCmd(ctx *cli.Context) error {
// Disable logging unless explicitly enabled.
if !ctx.IsSet("verbosity") && !ctx.IsSet("vmodule") {
- log.SetDefault(log.NewLogger(log.DiscardHandler()))
+ log.SetDefault(log.NewLogger(slog.DiscardHandler))
}
// Run the tests.
diff --git a/log/handler.go b/log/handler.go
index 56eff6671f..898d3968b0 100644
--- a/log/handler.go
+++ b/log/handler.go
@@ -13,29 +13,6 @@ import (
"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 {
mu sync.Mutex
wr io.Writer
diff --git a/log/root.go b/log/root.go
index c09a36b114..03007a07e1 100644
--- a/log/root.go
+++ b/log/root.go
@@ -12,7 +12,7 @@ var (
)
func init() {
- root = &logger{slog.New(DiscardHandler())}
+ root = &logger{slog.New(slog.DiscardHandler)}
}
// SetDefault sets the default global logger
|
2b0b3cd to
a6782a7
Compare
a6782a7 to
1535716
Compare
Contributor
Author
Done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.