From 52fe1a2e0f5eb28c9d17a735b0c3bd3a78415a1f Mon Sep 17 00:00:00 2001 From: EvieePy <29671945+EvieePy@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:07:07 +1000 Subject: [PATCH] Add some more verbose debug logging --- twitchio/client.py | 8 +++++++- twitchio/http.py | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/twitchio/client.py b/twitchio/client.py index 18a7137e..9543c5b6 100644 --- a/twitchio/client.py +++ b/twitchio/client.py @@ -256,6 +256,7 @@ def dispatch(self, event: str, payload: Any | None = None) -> None: if extra: listeners.add(extra) + logger.debug('Dispatching event: "%s" to %d listeners.', name, len(listeners)) _ = [asyncio.create_task(self._dispatch(listener, original=payload)) for listener in listeners] waits: set[asyncio.Task[None]] = set() @@ -489,6 +490,7 @@ async def close(self) -> None: await super().close() """ if self._has_closed: + logger.debug("Client was already set as closed. Disregarding call to close.") return self._has_closed = True @@ -497,10 +499,13 @@ async def close(self) -> None: if self._adapter._runner_task is not None: try: await self._adapter.close() - except Exception: + except Exception as e: + logger.debug("Encountered a cleanup error while closing the Client Web Adapter: %s. Disregarding.", e) pass sockets: list[Websocket] = [w for p in self._websockets.values() for w in p.values()] + logger.debug("Attempting cleanup on %d EventSub websocket connection(s).", len(sockets)) + for socket in sockets: await socket.close() @@ -513,6 +518,7 @@ async def close(self) -> None: self._http.cleanup() self.__waiter.set() + logger.debug("Cleanup completed on %r.", self) async def wait_until_ready(self) -> None: """|coro| diff --git a/twitchio/http.py b/twitchio/http.py index 4fbb12c6..e11a4b85 100644 --- a/twitchio/http.py +++ b/twitchio/http.py @@ -515,6 +515,8 @@ async def request(self, route: Route) -> RawResponse | str | None: ) as resp: data: RawResponse | str = await json_or_text(resp) + logger.debug("Request to %r with %s returned: status=%d", route, self.__class__.__qualname__, resp.status) + if resp.status >= 400: raise HTTPException( f"Request {route} failed with status {resp.status}: {data}",