- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.2k
 
fix: regression in go-log interop after slog migration #3418
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
base: master
Are you sure you want to change the base?
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
| // goLogBridge detects go-log's slog bridge via duck typing, without import dependency | ||
| type goLogBridge interface { | ||
| GoLogBridge() | ||
| } | 
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.
ℹ️ this is the gist of the solution that avoids depending on go-log in go.mod
| 
           Thanks lidel, I'll have a review by eod tomorrow.  | 
    
| return slog.New(&lazyBridgeHandler{ | ||
| system: system, | ||
| config: c, | ||
| }) | 
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.
Yeah, cannot rely on init() order across multiple packages.
👍
temporary revert until regression in libp2p/go-libp2p#3418 is resolved
temporary revert until regression in libp2p/go-libp2p#3418 is resolved
temporary revert until regression described in libp2p/go-libp2p#3418 is resolved
| 
           See #3419  | 
    
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.Reference
ipfs log tailipfs/kubo#11035go-logandgo-libp2p