forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 5
chore: logging #151
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
Merged
Merged
chore: logging #151
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b6d5cdb
chore: log registration of extras + precompile overriding
ARR4N a8e6668
test: `log.TypeOf()`
ARR4N 28c96d4
refactor: log type registration at `Info`
ARR4N 9ffcbdb
test: `TypeOf([typed nil])`
ARR4N 6211140
feat(log): `type Lazy func() slog.Value`
ARR4N 9e862fa
chore: lazily log differences in active precompiles
ARR4N 3996f8a
refactor: precise error message in `Lazy` test
ARR4N 4c699c8
feat: minimal `set` package
ARR4N d3101d1
chore: log `RulesAllowlistHooks` blocking only
ARR4N 87e1ff7
refactor(log): `TypeOf` returns a `Lazy`
ARR4N 888e350
chore: log from+to when tx blocked
ARR4N c0cd552
refactor: abstract `vm.EVM.canCreateContract()` hook wrapper
ARR4N a1aad6f
doc(log): correct `Lazy` comment
ARR4N 570fb7a
chore(ci): mark `eth/tracers/internal/tracetest` flaky
ARR4N bf67df4
chore: use lowercase log-attribute keys
ARR4N File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright 2025 the libevm authors. | ||
| // | ||
| // The libevm additions to go-ethereum are free software: you can redistribute | ||
| // them and/or modify them under the terms of the GNU Lesser General Public License | ||
| // as published by the Free Software Foundation, either version 3 of the License, | ||
| // or (at your option) any later version. | ||
| // | ||
| // The libevm additions are distributed in the hope that they will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
| // General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Lesser General Public License | ||
| // along with the go-ethereum library. If not, see | ||
| // <http://www.gnu.org/licenses/>. | ||
|
|
||
| package log | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "golang.org/x/exp/slog" | ||
| ) | ||
|
|
||
| // TypeOf returns a LogValuer that reports the concrete type of `v` as | ||
| // determined with the `%T` [fmt] verb. | ||
| func TypeOf(v any) slog.LogValuer { | ||
| return concreteTypeValue{v} | ||
| } | ||
|
|
||
| type concreteTypeValue struct{ v any } | ||
|
|
||
| func (v concreteTypeValue) LogValue() slog.Value { | ||
| return slog.StringValue(fmt.Sprintf("%T", v.v)) | ||
| } | ||
|
|
||
| // A Lazy function defers its execution until and if logging is performed. | ||
| type Lazy func() slog.Value | ||
|
|
||
| var _ slog.LogValuer = Lazy(nil) | ||
|
|
||
| // LogValue implements the [slog.LogValuer] interface. | ||
| func (l Lazy) LogValue() slog.Value { | ||
| return l() | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // Copyright 2025 the libevm authors. | ||
| // | ||
| // The libevm additions to go-ethereum are free software: you can redistribute | ||
| // them and/or modify them under the terms of the GNU Lesser General Public License | ||
| // as published by the Free Software Foundation, either version 3 of the License, | ||
| // or (at your option) any later version. | ||
| // | ||
| // The libevm additions are distributed in the hope that they will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
| // General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Lesser General Public License | ||
| // along with the go-ethereum library. If not, see | ||
| // <http://www.gnu.org/licenses/>. | ||
|
|
||
| package log | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "golang.org/x/exp/slog" | ||
| ) | ||
|
|
||
| func TestTypeOf(t *testing.T) { | ||
| type foo struct{} | ||
|
|
||
| tests := map[any]string{ | ||
| nil: "<nil>", | ||
| int(0): "int", | ||
| int(1): "int", | ||
| uint(0): "uint", | ||
| foo{}: "log.foo", | ||
| (*foo)(nil): "*log.foo", | ||
| } | ||
|
|
||
| for in, want := range tests { | ||
| got := TypeOf(in).LogValue() | ||
| assert.Equalf(t, want, got.String(), "TypeOf(%T(%[1]v))", in, in) | ||
| } | ||
| } | ||
|
|
||
| func TestLazy(t *testing.T) { | ||
| const ( | ||
| key = "theKey" | ||
| val = "theVal" | ||
| wantLogged = key + "=" + val | ||
| ) | ||
|
|
||
| var gotNumEvaluations int | ||
| fn := Lazy(func() slog.Value { | ||
| gotNumEvaluations++ | ||
| return slog.StringValue(val) | ||
| }) | ||
|
|
||
| var out bytes.Buffer | ||
| log := slog.New(slog.NewTextHandler(&out, &slog.HandlerOptions{ | ||
| Level: slog.LevelInfo, | ||
| })) | ||
| log.Info("", key, fn) | ||
| log.Debug("", "not evaluated", fn) | ||
|
|
||
| assert.Contains(t, out.String(), wantLogged, "evaluation of lazy function is logged") | ||
| assert.Equalf(t, 1, gotNumEvaluations, "number of evaluations of %T function", fn) | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than not being exported, this is now identical to the
[email protected]implementation.