Skip to content

Adding basic request logging. #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions intercom/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

import certifi
import json
import logging
import requests

logger = logging.getLogger('intercom.request')


class Request(object):

Expand All @@ -29,10 +32,27 @@ def send_request_to_path(cls, method, url, auth, params=None):
elif method == 'GET':
req_params['params'] = params
req_params['headers'] = headers

# request logging
if logger.isEnabledFor(logging.DEBUG):
logger.debug("Sending %s request to: %s", method, url)
logger.debug(" headers: %s", headers)
if method == 'GET':
logger.debug(" params: %s", req_params['params'])
else:
logger.debug(" params: %s", req_params['data'])

resp = requests.request(
method, url, timeout=cls.timeout,
auth=auth, verify=certifi.where(), **req_params)

# response logging
if logger.isEnabledFor(logging.DEBUG):
logger.debug("Response received from %s", url)
logger.debug(" encoding=%s status:%s",
resp.encoding, resp.status_code)
logger.debug(" content:\n%s", resp.content)

cls.raise_errors_on_failure(resp)
cls.set_rate_limit_details(resp)

Expand Down