Skip to content

fix(log): port upstream glog handler rewrite #33111 #35176, close #2876 - #2884

Merged
gzliudan merged 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:fix-issue-2876
Oct 28, 2026
Merged

gzliudan merged 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:fix-issue-2876

Conversation

@gzliudan

@gzliudan gzliudan commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Port go-ethereum's log/ rewrite to close out the remaining divergence inventory of #2876 (handler.go was already synced by #2837).

 GlogHandler
-  level    atomic.Int32            // global fast-track lets everything through
-  override atomic.Bool
-  patterns []pattern               // WithAttrs clones a snapshot:
-  siteCache map[uintptr]slog.Level //   child loggers ignore later changes
-  lock     sync.RWMutex
+  lock   sync.Mutex
+  config atomic.Pointer[glogConfig] // patterns + level + sync.Map callsite cache
+
+ glogWithAttrs                        // WithAttrs returns a wrapper that
+  base   *GlogHandler                 //   delegates back to the parent,
+  origin slog.Handler                 //   so children follow Verbosity/Vmodule
  • log/handler_glog.go — full rewrite from upstream log: allow –vmodule to downgrade log levels ethereum/go-ethereum#33111; --vmodule can now downgrade below the global verbosity, and child loggers follow later Verbosity/Vmodule changes on the parent.
  • log/logger_test.go — upstream regression tests TestLoggingWithVmoduleDowngrade, TestWithAttrsVerbosityChange, plus the out → out.String() fix in TestJSONHandler, and one repo-local TestLoggingCallsiteCacheInvalidation that drives two records through the same callsite, tightening the level via vmodule in one subtest and via verbosity in the other, to pin the per-config replacement of the callsite cache (the upstream tests log from different PCs and never hit it).
  • log/format.go — untouched here: the reflect.Ptr → reflect.Pointer rename from all: change reflect.Ptr to reflect.Pointer ethereum/go-ethereum#35176 is already in the tree (log/format.go:126).

Deliberately kept divergent from upstream (see commit body):

handler_glog.go is byte-identical to upstream master (2006f0836b) except the two SplitSeq lines, and logger_test.go matches upstream apart from the added TestLoggingCallsiteCacheInvalidation. The follow-ups after ethereum#33111 (ethereum#35055, ethereum#35074, ethereum#35176, ethereum#35141) are all in the tree already.

Behaviour changes

  • --vmodule may now downgrade: a rule whose level is above the global verbosity filters that file's records instead of only raising them.
  • Long-lived child loggers now follow the global verbosity. Raising --verbosity at runtime produces more output from loggers that used to stay frozen at their creation-time level — per-peer loggers in p2p/discover among them — so log volume can go up after upgrading.

Evidence

  • Before (new tests on old handler, dev-upgrade):

    --- FAIL: TestLoggingWithVmoduleDowngrade
        logger_test.go:56: expected 'after vmodule downgrade, this should be filtered' to NOT be logged
    --- FAIL: TestWithAttrsVerbosityChange
        logger_test.go:87: expected child logger to pick up verbosity change
    

    After (this branch):

    --- PASS: TestLoggingWithVmoduleDowngrade
    --- PASS: TestWithAttrsVerbosityChange
    --- PASS: TestLoggingCallsiteCacheInvalidation
    --- PASS: TestJSONHandler
    ok  github.com/XinFinOrg/XDPoSChain/log
    
  • diff -u against go-ethereum master: log/logger_test.go only adds TestLoggingCallsiteCacheInvalidation, log/handler_glog.go only the two SplitSeq lines.

Checks run: go test -count=1 ./log/... green, make all exit 0, make tidy clean, golangci-lint --new-from-rev 0 issues, gofmt/goimports clean.

Merge Danger

Door: two-way

Blast Radius: log package internals

Behavioral notes for reviewers: GlogHandler.Handle now checks the vmodule callsite cache before the global fast-track (this is the fix), and WithAttrs no longer copies config state. All external callers (internal/debug, cmd/bootnode, internal/debug/api.go) only use NewGlogHandler/Verbosity/Vmodule, whose signatures are unchanged.

Ref: go-ethereum ethereum#33111 (d07a946)
Ref: go-ethereum ethereum#35176 (7c9032d)
Close #2876

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8f909512-5df4-43d0-adb0-1755f934a429

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gzliudan
gzliudan force-pushed the fix-issue-2876 branch 2 times, most recently from a5c695f to 0482577 Compare October 26, 2026 05:32
@gzliudan
gzliudan force-pushed the fix-issue-2876 branch 2 times, most recently from 06d4096 to 6ed2440 Compare October 28, 2026 04:33
@gzliudan
gzliudan force-pushed the fix-issue-2876 branch 2 times, most recently from 743b2ea to ea20f37 Compare October 28, 2026 05:28
…35176, close XinFinOrg#2876

The old RWMutex + siteCache GlogHandler carried two behavioral gaps
inherited from upstream: --vmodule could not downgrade log levels below
the global verbosity (the global fast-track let everything through),
and child loggers created via WithAttrs kept a snapshot of the level
and patterns, so later Verbosity/Vmodule changes on the parent never
reached them.

Port go-ethereum's rewrite (ethereum#33111): GlogHandler now holds an
atomic.Pointer to an immutable glogConfig (patterns, level and a
sync.Map callsite cache), and WithAttrs returns a glogWithAttrs
wrapper that delegates back to the parent handler, fixing both gaps.
The two upstream regression tests (TestLoggingWithVmoduleDowngrade,
TestWithAttrsVerbosityChange) come along, plus the out.String() fix in
TestJSONHandler. The reflect.Ptr -> reflect.Pointer rename from ethereum#35176
is already in the tree, so log/format.go stays untouched here.

On top of the two upstream tests, TestLoggingCallsiteCacheInvalidation
drives two records through the same callsite, tightening the level via
Vmodule in one subtest and via Verbosity in the other, which is what
pins the per-config replacement of the callsite cache (the upstream
tests log from different PCs and never hit it).

Deliberately kept divergent from upstream: strings.SplitSeq in Vmodule
(this repo replaced strings.Split repo-wide in XinFinOrg#1698), and the package
level Enabled() helper in root.go (used by p2p/discover), so root.go
is left untouched.

Ref: go-ethereum ethereum#33111 (d07a946)
Ref: go-ethereum ethereum#35176 (7c9032d)
Close XinFinOrg#2876

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The logging-handler rewrite has no active review issues.

No open issues 🎉

What changed in this PR

Ports the upstream go-ethereum logging-handler rewrite to address the remaining logging divergence tracked in #2876, while preserving repository-specific behavior and public method signatures.

Changes:

  • Allows Vmodule rules to reduce verbosity below the global setting.
  • Shares configuration with child loggers so they follow runtime verbosity and module-filter changes.
  • Adds regression tests for filtering, child-log configuration updates, and callsite-cache invalidation, and corrects JSON test diagnostic formatting.
File Description
log/​logger_test.go Adds logging regression tests and fixes JSON failure-output formatting.
log/​handler_glog.go Replaces configuration snapshots with shared atomic configuration, per-configuration caching, and child-handler wrappers.

Review effort: Balanced

@gzliudan
gzliudan merged commit cb191a7 into XinFinOrg:dev-upgrade Oct 28, 2026
19 checks passed
@gzliudan
gzliudan deleted the fix-issue-2876 branch October 28, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants