Skip to content

Conversation

@lidel
Copy link
Member

@lidel lidel commented Oct 27, 2025

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 level and 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 adjust nat or net/identify to DEBUG level 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-log from zap backend to slog, 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-log as 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, 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.

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-log and go-libp2p 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, and it does not matter in thish order go-log and go-libp2p are 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

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
Comment on lines 43 to 46
// goLogBridge detects go-log's slog bridge via duck typing, without import dependency
type goLogBridge interface {
GoLogBridge()
}
Copy link
Member Author

Choose a reason for hiding this comment

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

ℹ️ this is the gist of the solution that avoids depending on go-log in go.mod

@MarcoPolo
Copy link
Collaborator

Thanks lidel, I'll have a review by eod tomorrow.

return slog.New(&lazyBridgeHandler{
system: system,
config: c,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, cannot rely on init() order across multiple packages.
👍

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
@MarcoPolo
Copy link
Collaborator

See #3419

@MarcoPolo MarcoPolo changed the title fix: regression in go-log interop after slog migration feat(gologshim): Add SetDefaultHandler Nov 4, 2025
@MarcoPolo MarcoPolo merged commit 3f09fa4 into master Nov 4, 2025
16 checks passed
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.

◆  [email protected] 3f09fa4 feat(gologshim): Add SetDefaultHandler (#3418)
◆  vsnqmzpw [email protected] 7b78dd6 fix(websocket): use debug level for http.Server errors
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.

4 participants