feat(debug): add MQTT_RAW_LOG env switch for unfiltered RX logging
All checks were successful
Nightly Build / build (push) Successful in 15m27s

Logs every incoming MQTT message on INFO regardless of topic, including
dedup'd duplicates and topics with no registered callback - useful for
capturing printer behavior the bridge doesn't normally surface without
needing to know the topic name in advance (the existing wildcard
subscribe already receives everything, this just makes it visible).
This commit is contained in:
2026-08-02 15:59:41 +02:00
parent ecc53cd7cb
commit 52baaa8f70

View File

@@ -144,6 +144,11 @@ class KobraXClient:
# Dedup: last hash per topic suffix to suppress repeated identical messages
self._last_rx_hash: dict[str, str] = {}
# Debug switch (MQTT_RAW_LOG=1): logs every RX message unfiltered on
# INFO, including dedup'd duplicates and topics with no registered
# callback - for capturing printer behavior the bridge doesn't
# normally surface (e.g. reverse-engineering a rejected command).
self._raw_log = os.environ.get("MQTT_RAW_LOG", "").strip().lower() in ("1", "true", "yes")
# Fields that change every tick and should be stripped before dedup-hashing
_VOLATILE = {"timestamp", "msgid", "progress", "curr_layer",
"curr_nozzle_temp", "curr_hotbed_temp",
@@ -422,6 +427,9 @@ class KobraXClient:
def _dispatch(self, topic: str, payload: dict):
suffix = "/".join(topic.split("/")[-2:])
if self._raw_log:
log.info("RX [raw] %s %s", topic, json.dumps(payload, ensure_ascii=False))
# Structured RX log with dedup suppression
h = self._dedup_hash(suffix, payload)
is_dup = self._last_rx_hash.get(suffix) == h