fix: reduce Telegram log spam from polling and conflict errors (#10027) (#10046)

Telegram long-polling floods the log in two ways:

1. python-telegram-bot performs getUpdates through httpx, which logs every request at INFO level. httpx/httpcore were missing from LogManager._NOISY_LOGGER_LEVELS, so those per-request lines (one every ~10s) leaked through.

2. _on_polling_error logged a full traceback for every polling error, including non-network errors such as Conflict (two bot instances polling the same token). Log a concise one-line message for non-network errors and keep the traceback only for NetworkError, which still needs it for recovery.
This commit is contained in:
玲因
2026-09-14 22:27:33 +08:00
committed by GitHub
parent 7ee03f2293
commit e79c0d7aa0
2 changed files with 11 additions and 2 deletions
+2
View File
@@ -203,6 +203,8 @@ class LogManager:
"asyncio": logging.WARNING,
"tzlocal": logging.WARNING,
"apscheduler": logging.WARNING,
"httpx": logging.WARNING,
"httpcore": logging.WARNING,
}
@classmethod
@@ -290,12 +290,19 @@ class TelegramPlatformAdapter(Platform):
await asyncio.sleep(self._polling_restart_delay)
def _on_polling_error(self, error: Exception) -> None:
# Non-network errors (e.g. Conflict when two bot instances poll the
# same token) have a clear cause; log a concise message instead of a
# full traceback to avoid filling the log.
if not isinstance(error, NetworkError):
logger.error(
f"Telegram polling request failed: {type(error).__name__}: {error!s}"
)
return
logger.error(
f"Telegram polling request failed: {type(error).__name__}: {error!s}",
exc_info=error,
)
if not isinstance(error, NetworkError):
return
if self._loop is None:
return