Skip to content

Commit 0148d3d

Browse files
committed
chore(logging)_: avoid logging spam by 3rd parties
iterates: status-im/status-desktop#16511
1 parent 34d2daf commit 0148d3d

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

logutils/override.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
logging "github.com/ipfs/go-log/v2"
88

9+
"go.uber.org/zap"
910
"go.uber.org/zap/zapcore"
1011
)
1112

@@ -54,15 +55,17 @@ func overrideCoreWithConfig(core *Core, settings LogSettings) error {
5455
core.UpdateSyncer(zapcore.Lock(os.Stderr))
5556
}
5657

57-
// FIXME: remove go-libp2p logging altogether
58-
// go-libp2p logger
59-
{
60-
lvl, err := logging.LevelFromString(settings.Level)
61-
if err != nil {
62-
return err
63-
}
64-
logging.SetAllLoggers(lvl)
65-
}
58+
// The go-libp2p logger shouldn't follow the app logger level,
59+
// as we don't have a way to control what and how it logs.
60+
// Assuming WarnLevel is enough to track potential issues and yet not spam the logs.
61+
logging.SetAllLoggers(logging.LogLevel(MaxLevel(level, zap.WarnLevel)))
6662

6763
return nil
6864
}
65+
66+
func MaxLevel(a, b zapcore.Level) zapcore.Level {
67+
if a > b {
68+
return a
69+
}
70+
return b
71+
}

wakuv2/message_publishing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (w *Waku) publishEnvelope(envelope *protocol.Envelope) {
8686
var err error
8787
// only used in testing to simulate going offline
8888
if w.cfg.SkipPublishToTopic {
89-
logger.Info("skipping publish to topic")
89+
logger.Debug("skipping publish to topic")
9090
err = errors.New("test send failure")
9191
} else {
9292
err = w.messageSender.Send(publish.NewRequest(w.ctx, envelope))

wakuv2/persistence/dbstore.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (d *DBStore) Query(query *storepb.HistoryQuery) (*storepb.Index, []gowakuPe
200200
start := time.Now()
201201
defer func() {
202202
elapsed := time.Since(start)
203-
d.log.Info(fmt.Sprintf("Loading records from the DB took %s", elapsed))
203+
d.log.Debug(fmt.Sprintf("Loading records from the DB took %s", elapsed))
204204
}()
205205

206206
sqlQuery := `SELECT id, receiverTimestamp, senderTimestamp, contentTopic, pubsubTopic, payload, version
@@ -361,7 +361,7 @@ func (d *DBStore) GetAll() ([]gowakuPersistence.StoredMessage, error) {
361361
start := time.Now()
362362
defer func() {
363363
elapsed := time.Since(start)
364-
d.log.Info("loading records from the DB", zap.Duration("duration", elapsed))
364+
d.log.Debug("loading records from the DB", zap.Duration("duration", elapsed))
365365
}()
366366

367367
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) {
381381
result = append(result, record)
382382
}
383383

384-
d.log.Info("DB returned records", zap.Int("count", len(result)))
384+
d.log.Debug("DB returned records", zap.Int("count", len(result)))
385385

386386
err = rows.Err()
387387
if err != nil {

wakuv2/waku.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func New(nodeKey *ecdsa.PrivateKey, fleet string, cfg *Config, logger *zap.Logge
290290
node.WithTopicHealthStatusChannel(waku.topicHealthStatusChan),
291291
node.WithKeepAlive(randomPeersKeepAliveInterval, allPeersKeepAliveInterval),
292292
node.WithLogger(logger),
293-
node.WithLogLevel(logger.Level()),
293+
node.WithLogLevel(logutils.MaxLevel(logger.Level(), zap.WarnLevel)), // Set min WarnLevel to avoid spamming app logs
294294
node.WithClusterID(cfg.ClusterID),
295295
node.WithMaxMsgSize(1024 * 1024),
296296
}
@@ -609,7 +609,7 @@ func (w *Waku) runPeerExchangeLoop() {
609609
w.logger.Debug("Peer exchange loop stopped")
610610
return
611611
case <-ticker.C:
612-
w.logger.Info("Running peer exchange loop")
612+
w.logger.Debug("Running peer exchange loop")
613613

614614
// We select only the nodes discovered via DNS Discovery that support peer exchange
615615
// 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 {
10211021
// Unsubscribe removes an installed message handler.
10221022
func (w *Waku) UnsubscribeMany(ids []string) error {
10231023
for _, id := range ids {
1024-
w.logger.Info("cleaning up filter", zap.String("id", id))
1024+
w.logger.Debug("cleaning up filter", zap.String("id", id))
10251025
ok := w.filters.Uninstall(id)
10261026
if !ok {
10271027
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
14451445

14461446
_, err := w.add(recvMessage, processImmediately)
14471447
if err != nil {
1448-
logger.Info("invalid envelope received", zap.Error(err))
1448+
logger.Debug("invalid envelope received", zap.Error(err))
14491449
trouble = true
14501450
}
14511451

0 commit comments

Comments
 (0)