summaryrefslogtreecommitdiff
path: root/swiftclient/client.py
diff options
context:
space:
mode:
authorLeah Klearman <lklrmn@gmail.com>2013-10-15 09:46:46 -0700
committerLeah Klearman <lklrmn@gmail.com>2013-10-17 16:05:36 -0700
commitb682935055fccbbbad988e75679dfc01b0869622 (patch)
tree11032fcf3f16315286f539e83032254335b2681a /swiftclient/client.py
parente08ec3ab8a28facc95977fc25c7e1e5381507591 (diff)
downloadpython-swiftclient-b682935055fccbbbad988e75679dfc01b0869622.tar.gz
enhance swiftclient logging
* log to debug for successes and info for errors * remove dead code, neither body or raw_body are sent in kwargs * include resp.reason and response headers in logging * remove trailing \n in logging. users who want them can set logging.basicConfig(format=FORMAT) * add --info option to swift cli Change-Id: If07af46cb377f3f3d70f6c4284037241d360a8b7
Diffstat (limited to 'swiftclient/client.py')
-rw-r--r--swiftclient/client.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py
index a95ce70..3bbbc54 100644
--- a/swiftclient/client.py
+++ b/swiftclient/client.py
@@ -54,9 +54,10 @@ logger.addHandler(NullHandler())
def http_log(args, kwargs, resp, body):
- if not logger.isEnabledFor(logging.DEBUG):
+ if not logger.isEnabledFor(logging.INFO):
return
+ # create and log equivalent curl command
string_parts = ['curl -i']
for element in args:
if element == 'HEAD':
@@ -65,21 +66,22 @@ def http_log(args, kwargs, resp, body):
string_parts.append(' -X %s' % element)
else:
string_parts.append(' %s' % element)
-
if 'headers' in kwargs:
for element in kwargs['headers']:
header = ' -H "%s: %s"' % (element, kwargs['headers'][element])
string_parts.append(header)
- logger.debug("REQ: %s\n" % "".join(string_parts))
- if 'raw_body' in kwargs:
- logger.debug("REQ BODY (RAW): %s\n" % (kwargs['raw_body']))
- if 'body' in kwargs:
- logger.debug("REQ BODY: %s\n" % (kwargs['body']))
+ # log response as debug if good, or info if error
+ if resp.status < 300:
+ log_method = logger.debug
+ else:
+ log_method = logger.info
- logger.debug("RESP STATUS: %s\n", resp.status)
+ log_method("REQ: %s" % "".join(string_parts))
+ log_method("RESP STATUS: %s %s" % (resp.status, resp.reason))
+ log_method("RESP HEADERS: %s", resp.getheaders())
if body:
- logger.debug("RESP BODY: %s\n", body)
+ log_method("RESP BODY: %s", body)
def quote(value, safe='/'):