Skip to content

Commit

Permalink
Add some more verbose debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
EvieePy committed Jan 7, 2025
1 parent 374e1b7 commit 52fe1a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion twitchio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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|
Expand Down
2 changes: 2 additions & 0 deletions twitchio/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down

0 comments on commit 52fe1a2

Please sign in to comment.