- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.2k
 
Gologshim runtime controlled handler #3419
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: feat/gologshim-use-slog-default
Are you sure you want to change the base?
Gologshim runtime controlled handler #3419
Conversation
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.
I think this makes the code cleaner/clearer. Your call @lidel
wire gologshim to go-log's slog bridge via init() in cmd/ipfs/kubo/start.go update go-libp2p to v0.44.1-0.20251029234611-789d14c6effe see libp2p/go-libp2p#3419
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 works for us also, pushed docs + some thoughts below:
On the trade-off here
Original #3418 required no changes in existing apps, just updating both go-log and go-libp2p to latest versions.
This PR requires every legacy application that used both go-log and go-libp2p to add this extra code:
  import (
      logging "github.com/ipfs/go-log/v2"
      "github.com/libp2p/go-libp2p/gologshim"
  )
  func init() {
      // After go-log's init() runs and installs slog bridge,
      // tell gologshim to use it      
      handler := slog.Default().Handler()      
      // Verify it's go-log's bridge
      type goLogBridge interface {
	      GoLogBridge()
      }
      if _, ok := handler.(goLogBridge); !ok {
	      panic("aborting startup: slog.Default() is not go-log's bridge, logs would be missing due to incorrect wiring")
      }
      // use the go-log bridge      
      gologshim.SetDefaultHandler(handler)
  }If this is the price to pay to fix logs, we can do the above in Kubo, Rainbow and every other application Shipyard maintains, but everyone else will be missing logs unless they do the same.
Just a trade-off decision.
Next steps
@MarcoPolo lgtm, i've tested this PR in ipfs/kubo#11039 and it also works for us (with the above extra code).
Up to you if you prefer implicit or explicit.
- If you prefer explicit, feel free to merge this PR into #3418, and then merge that (#3419+#3418).
 - If you are ok with implicit detection, this PR can be closed and only merge #3418
 
Either way, we would appreciate a release with a fix 🙏
lidel, take a look and let me know your thoughts. This is targeting your branch.
This removes the goLogBridge interface check and having to modify the default slog logger. Instead you explicitly set the handler via
gologshim.SetDefaultHandler.