diff --git a/mistralclient/api/httpclient.py b/mistralclient/api/httpclient.py index 6611cf58..55c21252 100644 --- a/mistralclient/api/httpclient.py +++ b/mistralclient/api/httpclient.py @@ -16,6 +16,20 @@ import requests +from mistralclient.openstack.common import log as logging + + +LOG = logging.getLogger(__name__) + + +def log_request(func): + def decorator(self, *args, **kwargs): + resp = func(self, *args, **kwargs) + LOG.debug("HTTP %s %s %d" % (resp.request.method, resp.url, + resp.status_code)) + return resp + return decorator + class HTTPClient(object): def __init__(self, base_url, token=None, project_id=None, user_id=None): @@ -24,11 +38,13 @@ class HTTPClient(object): self.project_id = project_id self.user_id = user_id + @log_request def get(self, url, headers=None): headers = self._update_headers(headers) return requests.get(self.base_url + url, headers=headers) + @log_request def post(self, url, body, headers=None): headers = self._update_headers(headers) content_type = headers.get('content-type', 'application/json') @@ -36,6 +52,7 @@ class HTTPClient(object): return requests.post(self.base_url + url, body, headers=headers) + @log_request def put(self, url, body, headers=None): headers = self._update_headers(headers) content_type = headers.get('content-type', 'application/json') @@ -43,6 +60,7 @@ class HTTPClient(object): return requests.put(self.base_url + url, body, headers=headers) + @log_request def delete(self, url, headers=None): headers = self._update_headers(headers)