feat(gologshim): Add SetDefaultHandler#3418
Merged
Conversation
The migration to slog in #3364 broke go-log's ability to adjust subsystem log levels at runtime via SetLogLevel() and control output formatting (colors, json). This was a key debugging feature that allowed changing log verbosity without restarting daemons. This fix detects go-log's slog bridge via duck typing and uses it when available, restoring dynamic level control and unified formatting. When go-log isn't present, gologshim falls back to standalone slog handlers as before. The lazy handler pattern solves initialization order issues where package-level loggers are created before go-log's bridge is installed. Users just need to update to this version of go-libp2p and go-log with ipfs/go-log#176 - no code changes or init() hacks required. Prerequisite for addressing ipfs/kubo#11035
lidel
commented
Oct 27, 2025
gologshim/gologshim.go
Outdated
Comment on lines
43
to
46
| // goLogBridge detects go-log's slog bridge via duck typing, without import dependency | ||
| type goLogBridge interface { | ||
| GoLogBridge() | ||
| } |
Member
Author
There was a problem hiding this comment.
ℹ️ this is the gist of the solution that avoids depending on go-log in go.mod
6 tasks
Collaborator
|
Thanks lidel, I'll have a review by eod tomorrow. |
gammazero
reviewed
Oct 29, 2025
| return slog.New(&lazyBridgeHandler{ | ||
| system: system, | ||
| config: c, | ||
| }) |
Contributor
There was a problem hiding this comment.
Yeah, cannot rely on init() order across multiple packages.
👍
gammazero
approved these changes
Oct 29, 2025
lidel
added a commit
to ipfs/boxo
that referenced
this pull request
Oct 29, 2025
temporary revert until regression in libp2p/go-libp2p#3418 is resolved
lidel
added a commit
to ipfs/boxo
that referenced
this pull request
Oct 29, 2025
temporary revert until regression in libp2p/go-libp2p#3418 is resolved
lidel
added a commit
to ipfs/boxo
that referenced
this pull request
Oct 29, 2025
temporary revert until regression described in libp2p/go-libp2p#3418 is resolved
Collaborator
|
See #3419 |
MarcoPolo
added a commit
that referenced
this pull request
Nov 4, 2025
A small release that adjust some noisy logging levels and adds a method for dynamically change the slog Handler for better integration with applications that use go-log. ◆ lidel@lidel.org 3f09fa4 feat(gologshim): Add SetDefaultHandler (#3418) ◆ vsnqmzpw lidel@lidel.org 7b78dd6 fix(websocket): use debug level for http.Server errors
rvagg
added a commit
to filecoin-project/lotus
that referenced
this pull request
Jan 5, 2026
go-libp2p v0.44+ uses slog instead of go-log, which breaks dynamic log level control via `lotus log set-level` for libp2p subsystems. Wire go-log's SlogHandler to both slog.SetDefault and gologshim to restore per-subsystem level control (dht, swarm2, bitswap, etc). Ref: ipfs/kubo#11039, libp2p/go-libp2p#3418
rvagg
added a commit
to filecoin-project/lotus
that referenced
this pull request
Jan 6, 2026
go-libp2p v0.44+ uses slog instead of go-log, which breaks dynamic log level control via `lotus log set-level` for libp2p subsystems. Wire go-log's SlogHandler to both slog.SetDefault and gologshim to restore per-subsystem level control (dht, swarm2, bitswap, etc). Ref: ipfs/kubo#11039, libp2p/go-libp2p#3418
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
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.
Problem
The migration to slog in
broke go-log's ability to adjust subsystem log levels at runtime via
SetLogLevel() and control output formatting (colors, json). This was a key debugging feature that allowed changing log verbosity without restarting daemons.Things like
ipfs log tail,ipfs log leveland Diagnostic screen in ipfs-webui (ipfs/ipfs-webui#2392) are broken with go-libp2p 0.44 – no go-libp2p logs are available, users are unable to, for example adjustnatornet/identifytoDEBUGlevel at runtime to do diagnostics.Second problem was that logs that worked due to env-variable being set to DEBUG ignored the user-preferred formatting.
Long term we may want to move
go-logfromzapbackend toslog, but in the meantime we need to unblock software that uses it to be able to use go-libp2p without regressions.cc @MarcoPolo @gammazero for visibility
Solution
First of all, a lot of time went into restoring this. It was not easy to fix without introducing
go-logas a dependency.To avoid depending on
go-log, this PR detects go-log's slog bridge via duck typing and uses it when available, restoring dynamic level control and unified formatting. When go-log isn't present,gologshimfalls back to standalone slog handlers as before.The lazy handler pattern solves initialization order issues where package-level loggers are created before go-log's bridge is installed.The intention of this PR is to fix regression allowing existing software to update to latest go-libp2p.
With this approach, users that depend on both
go-logandgo-libp2pjust need to update to this version ofgo-libp2pandgo-logwith ipfs/go-log#176 -no code changes orinit()hacks required, and it does not matter in thish ordergo-logandgo-libp2pare imported and initialized by existing apps. Things "just work" without breaking existing userbase.Important
Original version of this PR was rejected by go-libp2p maintainers, and instead go-libp2p 0.45 requires go-log users to manually set up wiring. See https://github.com/ipfs/go-log/releases/tag/v2.9.0 and #3419 (comment)
Reference
ipfs log tailipfs/kubo#11035go-logandgo-libp2p