chore: 優化「日誌的信噪比 (Signal-to-Noise Ratio)」

This commit is contained in:
swpa 2026-06-11 10:57:57 +08:00
parent 387d1d600a
commit 050936668d
1 changed files with 3 additions and 3 deletions

View File

@ -37,7 +37,7 @@ async def websocket_terminal(websocket: WebSocket, host: str, username: str, pas
except asyncio.CancelledError:
pass
except Exception as e:
logger.error("❌ [WS Forward Error] 讀取設備畫面時發生錯誤", exc_info=True)
logger.error(f"❌ [WS Forward Error] 讀取設備畫面時發生錯誤: {str(e)}")
async def forward_to_ssh():
try:
@ -60,7 +60,7 @@ async def websocket_terminal(websocket: WebSocket, host: str, username: str, pas
except asyncio.CancelledError:
pass
except Exception as e:
logger.error("❌ [SSH Forward Error] 寫入指令到設備時發生錯誤", exc_info=True)
logger.error(f"❌ [SSH Forward Error] 寫入指令到設備時發生錯誤: {str(e)}")
ws_task = asyncio.create_task(forward_to_ws())
ssh_task = asyncio.create_task(forward_to_ssh())
@ -91,7 +91,7 @@ async def websocket_terminal(websocket: WebSocket, host: str, username: str, pas
await websocket.close(code=4001, reason=safe_reason)
except:
pass
logger.error("❌ [Connection Error] 建立連線或執行過程中發生錯誤", exc_info=True)
logger.error(f"❌ [Connection Error] 建立連線或執行過程中發生錯誤: {str(e)}")
return # 🌟 提早結束,避免下方的 finally 再次執行 close 導致報錯
finally:
# 🌟 確保 process 與 conn 絕對被關閉,防止 Memory Leak