From 566e9e1578b9ae1ffaefd27420092bfb348d546a Mon Sep 17 00:00:00 2001 From: Patryk Osmaczko Date: Tue, 3 Dec 2024 23:58:03 +0100 Subject: [PATCH] chore(logging)_: avoid logging spam by 3rd parties iterates: status-im/status-desktop#16511 --- logutils/override.go | 21 ++++++++++++--------- wakuv2/message_publishing.go | 2 +- wakuv2/persistence/dbstore.go | 6 +++--- wakuv2/waku.go | 10 +++++----- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/logutils/override.go b/logutils/override.go index afb9b8cfc7c..b485064f03b 100644 --- a/logutils/override.go +++ b/logutils/override.go @@ -6,6 +6,7 @@ import ( logging "github.com/ipfs/go-log/v2" + "go.uber.org/zap" "go.uber.org/zap/zapcore" ) @@ -54,15 +55,17 @@ func overrideCoreWithConfig(core *Core, settings LogSettings) error { core.UpdateSyncer(zapcore.Lock(os.Stderr)) } - // FIXME: remove go-libp2p logging altogether - // go-libp2p logger - { - lvl, err := logging.LevelFromString(settings.Level) - if err != nil { - return err - } - logging.SetAllLoggers(lvl) - } + // The go-libp2p logger shouldn't follow the app logger level, + // as we don't have a way to control what and how it logs. + // Assuming InfoLevel is enough to track potential issues and yet not spam the logs. + logging.SetAllLoggers(logging.LogLevel(MaxLevel(level, zap.InfoLevel))) return nil } + +func MaxLevel(a, b zapcore.Level) zapcore.Level { + if a > b { + return a + } + return b +} diff --git a/wakuv2/message_publishing.go b/wakuv2/message_publishing.go index 93543bc6e39..c49532ec04f 100644 --- a/wakuv2/message_publishing.go +++ b/wakuv2/message_publishing.go @@ -86,7 +86,7 @@ func (w *Waku) publishEnvelope(envelope *protocol.Envelope) { var err error // only used in testing to simulate going offline if w.cfg.SkipPublishToTopic { - logger.Info("skipping publish to topic") + logger.Debug("skipping publish to topic") err = errors.New("test send failure") } else { err = w.messageSender.Send(publish.NewRequest(w.ctx, envelope)) diff --git a/wakuv2/persistence/dbstore.go b/wakuv2/persistence/dbstore.go index 4d75c0a56a0..5d5d889abe9 100644 --- a/wakuv2/persistence/dbstore.go +++ b/wakuv2/persistence/dbstore.go @@ -200,7 +200,7 @@ func (d *DBStore) Query(query *storepb.HistoryQuery) (*storepb.Index, []gowakuPe start := time.Now() defer func() { elapsed := time.Since(start) - d.log.Info(fmt.Sprintf("Loading records from the DB took %s", elapsed)) + d.log.Debug(fmt.Sprintf("Loading records from the DB took %s", elapsed)) }() sqlQuery := `SELECT id, receiverTimestamp, senderTimestamp, contentTopic, pubsubTopic, payload, version @@ -361,7 +361,7 @@ func (d *DBStore) GetAll() ([]gowakuPersistence.StoredMessage, error) { start := time.Now() defer func() { elapsed := time.Since(start) - d.log.Info("loading records from the DB", zap.Duration("duration", elapsed)) + d.log.Debug("loading records from the DB", zap.Duration("duration", elapsed)) }() rows, err := d.db.Query("SELECT id, receiverTimestamp, senderTimestamp, contentTopic, pubsubTopic, payload, version FROM store_messages ORDER BY senderTimestamp ASC") @@ -381,7 +381,7 @@ func (d *DBStore) GetAll() ([]gowakuPersistence.StoredMessage, error) { result = append(result, record) } - d.log.Info("DB returned records", zap.Int("count", len(result))) + d.log.Debug("DB returned records", zap.Int("count", len(result))) err = rows.Err() if err != nil { diff --git a/wakuv2/waku.go b/wakuv2/waku.go index 1fc541bd2f7..f8c48e9db40 100644 --- a/wakuv2/waku.go +++ b/wakuv2/waku.go @@ -289,8 +289,8 @@ func New(nodeKey *ecdsa.PrivateKey, fleet string, cfg *Config, logger *zap.Logge node.WithConnectionNotification(waku.connectionNotifChan), node.WithTopicHealthStatusChannel(waku.topicHealthStatusChan), node.WithKeepAlive(randomPeersKeepAliveInterval, allPeersKeepAliveInterval), - node.WithLogger(logger), - node.WithLogLevel(logger.Level()), + node.WithLogger(logger.Named("wakunode")), + node.WithLogLevel(logutils.MaxLevel(logger.Level(), zap.InfoLevel)), // Set min InfoLevel to avoid spamming app logs node.WithClusterID(cfg.ClusterID), node.WithMaxMsgSize(1024 * 1024), } @@ -609,7 +609,7 @@ func (w *Waku) runPeerExchangeLoop() { w.logger.Debug("Peer exchange loop stopped") return case <-ticker.C: - w.logger.Info("Running peer exchange loop") + w.logger.Debug("Running peer exchange loop") // We select only the nodes discovered via DNS Discovery that support peer exchange // We assume that those peers are running peer exchange according to infra config, @@ -1021,7 +1021,7 @@ func (w *Waku) GetFilter(id string) *common.Filter { // Unsubscribe removes an installed message handler. func (w *Waku) UnsubscribeMany(ids []string) error { for _, id := range ids { - w.logger.Info("cleaning up filter", zap.String("id", id)) + w.logger.Debug("cleaning up filter", zap.String("id", id)) ok := w.filters.Uninstall(id) if !ok { w.logger.Warn("could not remove filter with id", zap.String("id", id)) @@ -1445,7 +1445,7 @@ func (w *Waku) OnNewEnvelopes(envelope *protocol.Envelope, msgType common.Messag _, err := w.add(recvMessage, processImmediately) if err != nil { - logger.Info("invalid envelope received", zap.Error(err)) + logger.Debug("invalid envelope received", zap.Error(err)) trouble = true }