From 585ee6600923fc42fba0199d8567f3990da7276a Mon Sep 17 00:00:00 2001 From: "David J. Bianco" Date: Tue, 28 Jan 2025 10:48:29 -0500 Subject: [PATCH] Don't print ConnectionLost exceptions to the console These are far too frequent. We still log them, though, we just don't print them. --- SSH/ssh_server.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SSH/ssh_server.py b/SSH/ssh_server.py index acacb68..c452559 100755 --- a/SSH/ssh_server.py +++ b/SSH/ssh_server.py @@ -23,6 +23,7 @@ from langchain_core.chat_history import BaseChatMessageHistory, InMemoryChatMess from langchain_core.runnables.history import RunnableWithMessageHistory from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder from langchain_core.runnables import RunnablePassthrough +from asyncssh.misc import ConnectionLost class JSONFormatter(logging.Formatter): def format(self, record): @@ -74,7 +75,8 @@ class MySSHServer(asyncssh.SSHServer): def connection_lost(self, exc: Optional[Exception]) -> None: if exc: logger.error('SSH connection error', extra={"error": str(exc)}) - traceback.print_exception(exc) + if not isinstance(exc, ConnectionLost): + traceback.print_exception(exc) else: logger.info("SSH connection closed") # Ensure session summary is called on connection loss if attributes are set