Skip to content

Commit 291b87f

Browse files
committed
chore(mailserver)_: reduce debug logs size in messenger_mailserver
Logs from `messenger_mailserver` occupy 40 out of 100MB of data in my `geth.log`. Instead of extending `logger` with many parameters, such as `chatIDs`, `topic`, etc., the hash of those parameters is calucalted and kept as a context. iterates: #5889
1 parent 9eb2d97 commit 291b87f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

protocol/messenger_mailserver.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package protocol
22

33
import (
44
"context"
5+
"crypto/sha256"
6+
"encoding/hex"
57
"fmt"
68
"math"
79
"sort"
@@ -756,15 +758,15 @@ func processMailserverBatch(
756758
for _, t := range batch.Topics {
757759
topicStrings = append(topicStrings, t.String())
758760
}
759-
logger = logger.With(zap.Any("chatIDs", batch.ChatIDs),
761+
logger = logger.With(zap.String("batch hash", batch.Hash()))
762+
logger.Info("syncing topic",
763+
zap.Any("chatIDs", batch.ChatIDs),
760764
zap.String("fromString", time.Unix(int64(batch.From), 0).Format(time.RFC3339)),
761765
zap.String("toString", time.Unix(int64(batch.To), 0).Format(time.RFC3339)),
762766
zap.Any("topic", topicStrings),
763767
zap.Int64("from", int64(batch.From)),
764768
zap.Int64("to", int64(batch.To)))
765769

766-
logger.Info("syncing topic")
767-
768770
wg := sync.WaitGroup{}
769771
workWg := sync.WaitGroup{}
770772
workCh := make(chan work, 1000) // each batch item is split in 10 topics bunch and sent to this channel
@@ -959,6 +961,12 @@ type MailserverBatch struct {
959961
ChatIDs []string
960962
}
961963

964+
func (mb *MailserverBatch) Hash() string {
965+
data := fmt.Sprintf("%d%d%s%s%v%v", mb.From, mb.To, mb.Cursor, mb.PubsubTopic, mb.Topics, mb.ChatIDs)
966+
hash := sha256.Sum256([]byte(data))
967+
return hex.EncodeToString(hash[:4])
968+
}
969+
962970
func (m *Messenger) SyncChatFromSyncedFrom(chatID string) (uint32, error) {
963971
chat, ok := m.allChats.Load(chatID)
964972
if !ok {

0 commit comments

Comments
 (0)