From 715848075511d62d7538b3998ff5935802bac08b Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Tue, 11 Nov 2025 21:06:31 +0100 Subject: [PATCH] fix(webrtc): use debug level for pion errors Pre-v0.44 (Working State): PR #2915 deliberately downgraded all pion logs to Debug level because "Pion logs are too noisy and have invalid log levels". This worked correctly for ~1 year without issues. v0.44.0 (Regression): PR #3364 migrated from go-log/v2 to log/slog but accidentally reverted the pion log level downgrade. The migration kept the comment claiming logs were downgraded but changed the implementation to log Error/Warn/Info at their face values, causing routine connection events to spam error logs. Similar to PR #3413 which fixed this issue for websocket transport, WebRTC transport needs the same treatment. Pion logs client disconnects, protocol mismatches, and state races as ERROR/WARN, but these are normal operational noise from a service perspective, not actual errors requiring operator attention. This restores PR #2915 behavior: downgrade all pion logs to Debug level. Fixes https://github.com/ipfs/kubo/issues/11053 --- p2p/transport/webrtc/logger.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/p2p/transport/webrtc/logger.go b/p2p/transport/webrtc/logger.go index e2d1aabb82..d9a8f6f35a 100644 --- a/p2p/transport/webrtc/logger.go +++ b/p2p/transport/webrtc/logger.go @@ -14,10 +14,11 @@ var log = logging.Logger("webrtc-transport") // pionLog is the logger provided to pion for internal logging var pionLog = logging.Logger("webrtc-transport-pion") -// pionLogger wraps the StandardLogger interface to provide a LeveledLogger interface -// as expected by pion -// Pion logs are too noisy and have invalid log levels. pionLogger downgrades all the -// logs to debug +// pionLogger adapts pion's logger to go-libp2p's semantics. +// Pion logs routine connection events (client disconnects, protocol mismatches, +// state races) as ERROR/WARN, but these are normal operational noise from a +// service perspective. We downgrade all pion logs to DEBUG to prevent log spam +// while preserving debuggability when needed. type pionLogger struct { *slog.Logger } @@ -37,32 +38,32 @@ func (l pionLogger) Debugf(s string, args ...interface{}) { } func (l pionLogger) Error(s string) { - l.Logger.Error(s) + l.Logger.Debug(s) } func (l pionLogger) Errorf(s string, args ...interface{}) { - if l.Logger.Enabled(context.Background(), slog.LevelError) { - l.Logger.Error(fmt.Sprintf(s, args...)) + if l.Logger.Enabled(context.Background(), slog.LevelDebug) { + l.Logger.Debug(fmt.Sprintf(s, args...)) } } func (l pionLogger) Info(s string) { - l.Logger.Info(s) + l.Logger.Debug(s) } func (l pionLogger) Infof(s string, args ...interface{}) { - if l.Logger.Enabled(context.Background(), slog.LevelInfo) { - l.Logger.Info(fmt.Sprintf(s, args...)) + if l.Logger.Enabled(context.Background(), slog.LevelDebug) { + l.Logger.Debug(fmt.Sprintf(s, args...)) } } func (l pionLogger) Warn(s string) { - l.Logger.Warn(s) + l.Logger.Debug(s) } func (l pionLogger) Warnf(s string, args ...interface{}) { - if l.Logger.Enabled(context.Background(), slog.LevelWarn) { - l.Logger.Warn(fmt.Sprintf(s, args...)) + if l.Logger.Enabled(context.Background(), slog.LevelDebug) { + l.Logger.Debug(fmt.Sprintf(s, args...)) } }