Skip to content

Conversation

@MarcoPolo
Copy link
Contributor

related to libp2p/go-libp2p#3362.

  • Changes all logging to be structured.
  • Removes the global logger. This is really nice for tests since you can now see which ID a log line belongs to.
  • Adds a sub-logger just for RPC messages. In my experience the RPC messages are the only thing I need to debug issues. It's nice to have the structured log there I can use easily without having to futz around with tracers.
  • Implements the LogValuer interface for the RPC pb type. In practice it's much easier to update this implementation than it is to maintain a separate trace protobuf system.

Currently inlines an internal gologshim.go package to maintain ipfs/go-log environment variable compatibility. Once libp2p/go-libp2p#3364 is merged, we can use the gologshim package in go-libp2p.

gossipsub.go Outdated
score := gs.score.Score(p)
if score < gs.gossipThreshold {
log.Debugf("IWANT: ignoring peer %s with score below threshold [score = %f]", p, score)
gs.p.logger.Debug("IWANT: ignoring peer with score below threshold", "peer", p, "score", score)
Copy link
Member

@sukunrt sukunrt Sep 11, 2025

Choose a reason for hiding this comment

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

NIT: I'd just have the logger reference on gs. So we can do gs.logger.Debug

Comment on lines +520 to +521
ps.rpcLogger = slog.New(ps.logger.Handler().WithAttrs([]slog.Attr{slog.String("system", "pubsub/rpc")}))
}
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to enable only these rpc logs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. You pass a custom rpcLogger

@MarcoPolo MarcoPolo merged commit f8635a5 into master Sep 15, 2025
9 checks passed
@MarcoPolo MarcoPolo deleted the marco/slog branch September 15, 2025 17:29
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.

3 participants