diff --git a/bot.py b/bot.py index a149f39..d15945f 100644 --- a/bot.py +++ b/bot.py @@ -102,6 +102,24 @@ logging.basicConfig( ) log = logging.getLogger("signal-bot") + +class _RawReceiptNoiseFilter(logging.Filter): + """signalbot logs every received envelope at INFO via `[Raw Message] {json}`. + On a busy account that's a flood of delivery/read receipts, typing indicators, + and read-sync messages that rotates the journal down to ~1 minute and buries + real traffic. Suppress the content-free envelopes (anything without a + `dataMessage`) unless the signalbot logger is explicitly set to DEBUG — so they + stay capturable when you actually want to debug raw traffic, but don't spam INFO.""" + + def filter(self, record: logging.LogRecord) -> bool: + msg = record.getMessage() + if msg.startswith("[Raw Message] ") and '"dataMessage"' not in msg: + return logging.getLogger("signalbot").isEnabledFor(logging.DEBUG) + return True + + +logging.getLogger("signalbot").addFilter(_RawReceiptNoiseFilter()) + # (group_id, sender) -> {"b64": ..., "time": monotonic}. Keyed per sender so a # stranger's later video doesn't silently become the target of your /speed or # /rev; _get_video falls back to the group's latest video when you have none.