Skip to content

Commit

Permalink
Add Aiohttp Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Icebluewolf committed Sep 15, 2024
1 parent 8459357 commit 7bad2f7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,24 @@ async def close(self) -> None:
# login management

async def static_login(self, token: str) -> user.User:
import logging

async def on_request_start(session, context, params: aiohttp.TraceRequestStartParams):
# breakpoint()
logging.getLogger('aiohttp.client').debug(f'Starting request <{params}> <{session}> <{context}>')

async def on_request_chunk_sent(session, context, params: aiohttp.TraceRequestChunkSentParams):
with open("output.txt", "a") as file:
file.write(str(params.chunk))
# logging.getLogger('aiohttp.client').debug(f'Sent Chunk <{params}>')

trace_config = aiohttp.TraceConfig()
trace_config.on_request_start.append(on_request_start)
trace_config.on_request_chunk_sent.append(on_request_chunk_sent)

# Necessary to get aiohttp to stop complaining about session creation
self.__session = aiohttp.ClientSession(
connector=self.connector, ws_response_class=DiscordClientWebSocketResponse
connector=self.connector, ws_response_class=DiscordClientWebSocketResponse, trace_configs=[trace_config]
)
old_token = self.token
self.token = token
Expand Down

0 comments on commit 7bad2f7

Please sign in to comment.