浏览代码

Add trace logs around sending messages

Tulir Asokan 4 年之前
父节点
当前提交
7315aa7ab4
共有 2 个文件被更改,包括 10 次插入0 次删除
  1. 6 0
      mauigpapi/mqtt/conn.py
  2. 4 0
      mautrix_instagram/portal.py

+ 6 - 0
mauigpapi/mqtt/conn.py

@@ -209,7 +209,9 @@ class AndroidMQTT:
         try:
             waiter = self._publish_waiters[mid]
         except KeyError:
+            self.log.trace(f"Got publish confirmation for {mid}, but no waiters")
             return
+        self.log.trace(f"Got publish confirmation for {mid}")
         waiter.set_result(None)
 
     # region Incoming event parsing
@@ -451,7 +453,9 @@ class AndroidMQTT:
         if isinstance(payload, str):
             payload = payload.encode("utf-8")
         payload = zlib.compress(payload, level=9)
+        self.log.trace(f"Publishing message in {topic.name}/{topic.encoded}: {payload}")
         info = self._client.publish(topic.encoded, payload, qos=1)
+        self.log.trace(f"Published message ID: {info.mid}")
         fut = asyncio.Future()
         self._publish_waiters[info.mid] = fut
         return fut
@@ -462,6 +466,8 @@ class AndroidMQTT:
             fut = asyncio.Future()
             self._response_waiters[response] = fut
             await self.publish(topic, payload)
+            self.log.trace(f"Request published to {topic.name}, "
+                           f"waiting for response {response.name}")
             return await fut
 
     async def iris_subscribe(self, seq_id: int, snapshot_at_ms: int) -> None:

+ 4 - 0
mautrix_instagram/portal.py

@@ -181,6 +181,7 @@ class Portal(DBPortal, BasePortal):
             text = message.body
             if message.msgtype == MessageType.EMOTE:
                 text = f"/me {text}"
+            self.log.trace(f"Sending Matrix text from {event_id} with request ID {request_id}")
             resp = await sender.mqtt.send_text(self.thread_id, text=text,
                                                client_context=request_id)
         elif message.msgtype.is_media:
@@ -199,7 +200,9 @@ class Portal(DBPortal, BasePortal):
                         data = out.getvalue()
                 mime_type = "image/jpeg"
             if mime_type == "image/jpeg":
+                self.log.trace(f"Uploading photo from {event_id}")
                 upload_resp = await sender.client.upload_jpeg_photo(data)
+                self.log.trace(f"Broadcasting uploaded photo with request ID {request_id}")
                 # TODO is it possible to do this with MQTT?
                 resp = await sender.client.broadcast(self.thread_id,
                                                      ThreadItemType.CONFIGURE_PHOTO,
@@ -214,6 +217,7 @@ class Portal(DBPortal, BasePortal):
             self.log.debug(f"Unhandled Matrix message {event_id}: "
                            f"unknown msgtype {message.msgtype}")
             return
+        self.log.trace(f"Got response to message send {request_id}: {resp}")
         if resp.status != "ok":
             self.log.warning(f"Failed to handle {event_id}: {resp}")
             await self._send_bridge_error(resp.payload.message)