Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(channels): stdlib logging placeholders in feishu

shadowinlife982c6f94b416
diff --git a/agent/src/channels/feishu.py b/agent/src/channels/feishu.py
index 0ad594f83..e36c06569 100644
--- a/agent/src/channels/feishu.py
+++ b/agent/src/channels/feishu.py
@@ -838,7 +838,7 @@ class FeishuChannel(BaseChannel):
try:
self._ws_client.start()
except Exception as e:
- self.logger.warning("WebSocket error: {}", e)
+ self.logger.warning("WebSocket error: %s", e)
if self._running:
time.sleep(5)
finally:
@@ -856,7 +856,7 @@ class FeishuChannel(BaseChannel):
None, self._fetch_bot_open_id
)
if self._bot_open_id:
- self.logger.info("bot open_id: {}", self._bot_open_id)
+ self.logger.info("bot open_id: %s", self._bot_open_id)
else:
self.logger.warning("Could not fetch bot open_id; @mention matching may be inaccurate")
@@ -897,10 +897,10 @@ class FeishuChannel(BaseChannel):
data = json.loads(response.raw.content)
bot = (data.get("data") or data).get("bot") or data.get("bot") or {}
return bot.get("open_id")
- self.logger.warning("Failed to get bot info: code={}, msg={}", response.code, response.msg)
+ self.logger.warning("Failed to get bot info: code=%s, msg=%s", response.code, response.msg)
return None
except Exception as e:
- self.logger.warning("Error fetching bot info: {}", e)
+ self.logger.warning("Error fetching bot info: %s", e)
return None
@staticmethod
@@ -1021,14 +1021,14 @@ class FeishuChannel(BaseChannel):
if not response.success():
self.logger.warning(
- "Failed to add reaction: code={}, msg={}", response.code, response.msg
+ "Failed to add reaction: code=%s, msg=%s", response.code, response.msg
)
return None
else:
- self.logger.debug("Added {} reaction to message {}", emoji_type, message_id)
+ self.logger.debug("Added %s reaction to message %s", emoji_type, message_id)
return response.data.reaction_id if response.data else None
except Exception as e:
- self.logger.warning("Error adding reaction: {}", e)
+ self.logger.warning("Error adding reaction: %s", e)
return None
async def _add_reaction(self, message_id: str, emoji_type: str = "THUMBSUP") -> str | None:
@@ -1060,13 +1060,13 @@ class FeishuChannel(BaseChannel):
response = self._client.im.v1.message_reaction.delete(request)
if response.success():
- self.logger.debug("Removed reaction {} from message {}", reaction_id, message_id)
+ self.logger.debug("Removed reaction %s from message %s", reaction_id, message_id)
else:
self.logger.debug(
- "Failed to remove reaction: code={}, msg={}", response.code, response.msg
+ "Failed to remove reaction: code=%s, msg=%s", response.code, response.msg
)
except Exception as e:
- self.logger.debug("Error removing reaction: {}", e)
+ self.logger.debug("Error removing reaction: %s", e)
async def _remove_reaction(self, message_id: str, reaction_id: str) -> None:
"""
@@ -1088,7 +1088,7 @@ class FeishuChannel(BaseChannel):
try:
task.result()
except Exception as exc:
- self.logger.warning("Background task failed: {}", exc)
+ self.logger.warning("Background task failed: %s", exc)
def _on_reaction_added(self, message_id: str, task: asyncio.Task) -> None:
"""Callback: store reaction_id after background add-reaction completes."""
@@ -1405,15 +1405,15 @@ class FeishuChannel(BaseChannel):
response = self._client.im.v1.image.create(request)
if response.success():
image_key = response.data.image_key
- self.logger.debug("Uploaded image {}: {}", os.path.basename(file_path), image_key)
+ self.logger.debug("Uploaded image %s: %s", os.path.basename(file_path), image_key)
return image_key
else:
self.logger.error(
- "Failed to upload image: code={}, msg={}", response.code, response.msg
+ "Failed to upload image: code=%s, msg=%s", response.code, response.msg
)
return None
except Exception:
- self.logger.exception("Error uploading image {}", file_path)
+ self.logger.exception("Error uploading image %s", file_path)
return None
def _upload_file_sync(self, file_path: str) -> str | None:
@@ -1439,15 +1439,15 @@ class FeishuChannel(BaseChannel):
response = self._client.im.v1.file.create(request)
if response.success():
file_key = response.data.file_key
- self.logger.debug("Uploaded file {}: {}", file_name, file_key)
+ self.logger.debug("Uploaded file %s: %s", file_name, file_key)
return file_key
else:
self.logger.error(
- "Failed to upload file: code={}, msg={}", response.code, response.msg
+ "Failed to upload file: code=%s, msg=%s", response.code, response.msg
)
return None
except Exception:
- self.logger.exception("Error uploading file {}", file_path)
+ self.logger.exception("Error uploading file %s", file_path)
return None
def _download_image_sync(
@@ -1473,11 +1473,11 @@ class FeishuChannel(BaseChannel):
return file_data, response.file_name
else:
self.logger.error(
- "Failed to download image: code={}, msg={}", response.code, response.msg
+ "Failed to download image: code=%s, msg=%s", response.code, response.msg
)
return None, None
except Exception:
- self.logger.exception("Error downloading image {}", image_key)
+ self.logger.exception("Error downloading image %s", image_key)
return None, None
def _download_file_sync(
@@ -1507,14 +1507,14 @@ class FeishuChannel(BaseChannel):
return file_data, response.file_name
else:
self.logger.error(
- "Failed to download {}: code={}, msg={}",
+ "Failed to download %s: code=%s, msg=%s",
resource_type,
response.code,
response.msg,
)
return None, None
except Exception:
- self.logger.exception("Error downloading {} {}", resource_type, file_key)
+ self.logger.exception("Error downloading %s %s", resource_type, file_key)
return None, None
@staticmethod
@@ -1558,10 +1558,10 @@ class FeishuChannel(BaseChannel):
elif msg_type in ("audio", "file", "media"):
file_key = content_json.get("file_key")
if not file_key:
- self.logger.warning("{} message missing file_key: {}", msg_type, content_json)
+ self.logger.warning("%s message missing file_key: %s", msg_type, content_json)
return None, f"[{msg_type}: missing file_key]"
if not message_id:
- self.logger.warning("{} message missing message_id", msg_type)
+ self.logger.warning("%s message missing message_id", msg_type)
return None, f"[{msg_type}: missing message_id]"
fallback_filename = file_key[:16]
@@ -1570,7 +1570,7 @@ class FeishuChannel(BaseChannel):
)
if not data:
- self.logger.warning("{} download failed: file_key={}", msg_type, file_key)
+ self.logger.warning("%s download failed: file_key=%s", msg_type, file_key)
return None, f"[{msg_type}: download failed]"
if not filename:
@@ -1587,7 +1587,7 @@ class FeishuChannel(BaseChannel):
file_path = media_dir / filename
file_path.write_bytes(data)
path_str = str(file_path)
- self.logger.debug("Downloaded {} to {}", msg_type, path_str)
+ self.logger.debug("Downloaded %s to %s", msg_type, path_str)
return path_str, f"[{msg_type}: {path_str}]"
return None, f"[{msg_type}: download failed]"
@@ -1606,7 +1606,7 @@ class FeishuChannel(BaseChannel):
response = self._client.im.v1.message.get(request)
if not response.success():
self.logger.debug(
- "could not fetch parent message {}: code={}, msg={}",
+ "could not fetch parent message %s: code=%s, msg=%s",
message_id,
response.code,
response.msg,
@@ -1638,7 +1638,7 @@ class FeishuChannel(BaseChannel):
text = text[: self._REPLY_CONTEXT_MAX_LEN] + "..."
return f"[Reply to: {text}]"
except Exception as e:
- self.logger.debug("error fetching parent message {}: {}", message_id, e)
+ self.logger.debug("error fetching parent message %s: %s", message_id, e)
return None
def _reply_message_sync(self, parent_message_id: str, msg_type: str, content: str, *, reply_in_thread: bool = False) -> bool:
@@ -1663,17 +1663,17 @@ class FeishuChannel(BaseChannel):
response = self._client.im.v1.message.reply(request)
if not response.success():
self.logger.error(
- "Failed to reply to message {}: code={}, msg={}, log_id={}",
+ "Failed to reply to message %s: code=%s, msg=%s, log_id=%s",
parent_message_id,
response.code,
response.msg,
response.get_log_id(),
)
return False
- self.logger.debug("reply sent to message {}", parent_message_id)
+ self.logger.debug("reply sent to message %s", parent_message_id)
return True
except Exception:
- self.logger.exception("Error replying to message {}", parent_message_id)
+ self.logger.exception("Error replying to message %s", parent_message_id)
return False
def _should_use_reply_in_thread(self, metadata: dict[str, Any]) -> bool:
@@ -1713,7 +1713,7 @@ class FeishuChannel(BaseChannel):
response = self._client.im.v1.message.create(request)
if not response.success():
self.logger.error(
- "Failed to send {} message: code={}, msg={}, log_id={}",
+ "Failed to send %s message: code=%s, msg=%s, log_id=%s",
msg_type,
response.code,
response.msg,
@@ -1721,10 +1721,10 @@ class FeishuChannel(BaseChannel):
)
return None
msg_id = getattr(response.data, "message_id", None)
- self.logger.debug("{} message sent to {}: {}", msg_type, receive_id, msg_id)
+ self.logger.debug("%s message sent to %s: %s", msg_type, receive_id, msg_id)
return msg_id
except Exception:
- self.logger.exception("Error sending {} message", msg_type)
+ self.logger.exception("Error sending %s message", msg_type)
return None
def _create_streaming_card_sync(
@@ -1765,7 +1765,7 @@ class FeishuChannel(BaseChannel):
response = self._client.cardkit.v1.card.create(request)
if not response.success():
self.logger.warning(
- "Failed to create streaming card: code={}, msg={}", response.code, response.msg
+ "Failed to create streaming card: code=%s, msg=%s", response.code, response.msg
)
return None
card_id = getattr(response.data, "card_id", None)
@@ -1785,11 +1785,11 @@ class FeishuChannel(BaseChannel):
if sent:
return card_id
self.logger.warning(
- "Created streaming card {} but failed to send it to {}", card_id, chat_id
+ "Created streaming card %s but failed to send it to %s", card_id, chat_id
)
return None
except Exception as e:
- self.logger.warning("Error creating streaming card: {}", e)
+ self.logger.warning("Error creating streaming card: %s", e)
return None
def _stream_update_text_sync(self, card_id: str, content: str, sequence: int) -> bool:
@@ -1815,7 +1815,7 @@ class FeishuChannel(BaseChannel):
response = self._client.cardkit.v1.card_element.content(request)
if not response.success():
self.logger.warning(
- "Failed to stream-update card {}: code={}, msg={}",
+ "Failed to stream-update card %s: code=%s, msg=%s",
card_id,
response.code,
response.msg,
@@ -1823,7 +1823,7 @@ class FeishuChannel(BaseChannel):
return False
return True
except Exception as e:
- self.logger.warning("Error stream-updating card {}: {}", card_id, e)
+ self.logger.warning("Error stream-updating card %s: %s", card_id, e)
return False
def _set_streaming_mode_sync(self, card_id: str, enabled: bool, sequence: int) -> bool:
@@ -1847,7 +1847,7 @@ class FeishuChannel(BaseChannel):
response = self._client.cardkit.v1.card.settings(request)
if not response.success():
self.logger.warning(
- "Failed to set streaming={} on card {}: code={}, msg={}",
+ "Failed to set streaming=%s on card %s: code=%s, msg=%s",
enabled,
card_id,
response.code,
@@ -1856,7 +1856,7 @@ class FeishuChannel(BaseChannel):
return False
return True
except Exception as e:
- self.logger.warning("Error setting streaming={} on card {}: {}", enabled, card_id, e)
+ self.logger.warning("Error setting streaming=%s on card %s: %s", enabled, card_id, e)
return False
def _close_streaming_mode_sync(self, card_id: str, sequence: int) -> bool:
@@ -1956,7 +1956,7 @@ class FeishuChannel(BaseChannel):
buf.sequence,
)
self.logger.warning(
- "Streaming card {} final update failed, falling back to regular card",
+ "Streaming card %s final update failed, falling back to regular card",
buf.card_id,
)
for chunk in self._split_elements_by_table_limit(
@@ -2133,7 +2133,7 @@ class FeishuChannel(BaseChannel):
for file_path in msg.media:
if not os.path.isfile(file_path):
- self.logger.warning("Media file not found: {}", file_path)
+ self.logger.warning("Media file not found: %s", file_path)
continue
ext = os.path.splitext(file_path)[1].lower()
if ext in self._IMAGE_EXTS:
@@ -2265,8 +2265,8 @@ class FeishuChannel(BaseChannel):
message = event.message
sender = event.sender
- self.logger.debug("raw message: {}", message.content)
- self.logger.debug("mentions: {}", getattr(message, "mentions", None))
+ self.logger.debug("raw message: %s", message.content)
+ self.logger.debug("mentions: %s", getattr(message, "mentions", None))
message_id = message.message_id