Browse Source

Make logging for HTTP requests more useful.

pull/146/merge
Rapptz 9 years ago
parent
commit
fa0c98da4c
  1. 9
      discord/http.py

9
discord/http.py

@ -64,8 +64,8 @@ class HTTPClient:
CHANNELS = API_BASE + '/channels' CHANNELS = API_BASE + '/channels'
APPLICATIONS = API_BASE + '/oauth2/applications' APPLICATIONS = API_BASE + '/oauth2/applications'
SUCCESS_LOG = '{method} {url} with {json} has received {text}' SUCCESS_LOG = '{method} {url} has received {text}'
REQUEST_LOG = '{method} {url} has returned {status}' REQUEST_LOG = '{method} {url} with {json} has returned {status}'
def __init__(self, connector=None, *, loop=None): def __init__(self, connector=None, *, loop=None):
self.loop = asyncio.get_event_loop() if loop is None else loop self.loop = asyncio.get_event_loop() if loop is None else loop
@ -103,15 +103,14 @@ class HTTPClient:
with (yield from lock): with (yield from lock):
for tries in range(5): for tries in range(5):
r = yield from self.session.request(method, url, **kwargs) r = yield from self.session.request(method, url, **kwargs)
log.debug(self.REQUEST_LOG.format(method=method, url=url, status=r.status)) log.debug(self.REQUEST_LOG.format(method=method, url=url, status=r.status, json=kwargs.get('data')))
try: try:
# even errors have text involved in them so this is safe to call # even errors have text involved in them so this is safe to call
data = yield from json_or_text(r) data = yield from json_or_text(r)
# the request was successful so just return the text/json # the request was successful so just return the text/json
if 300 > r.status >= 200: if 300 > r.status >= 200:
log.debug(self.SUCCESS_LOG.format(method=method, url=url, log.debug(self.SUCCESS_LOG.format(method=method, url=url, text=data))
json=kwargs.get('data'), text=data))
return data return data
# we are being rate limited # we are being rate limited

Loading…
Cancel
Save