From d3603535d2f47580bf49520048af1f27adea3e7c Mon Sep 17 00:00:00 2001
From: Dean Troyer <dtroyer@gmail.com>
Date: Thu, 13 Dec 2012 14:52:54 -0600
Subject: [PATCH] Port some additional logging changes from novaclient

* Allows capture of timestamps prior to and after request for timing
  https://review.openstack.org/11519
* Add -X to DELETE and PUT in debug mode
  https://review.openstack.org/12069
* Show request body in curl command
  https://review.openstack.org/12203

Change-Id: I0d87ab6b3c2b35ff843323cb818915e03993a844
---
 cinderclient/client.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/cinderclient/client.py b/cinderclient/client.py
index 1e3652eb3..be6107297 100644
--- a/cinderclient/client.py
+++ b/cinderclient/client.py
@@ -71,13 +71,13 @@ class HTTPClient(httplib2.Http):
             self._logger.setLevel(logging.DEBUG)
             self._logger.addHandler(ch)
 
-    def http_log(self, args, kwargs, resp, body):
+    def http_log_req(self, args, kwargs):
         if not self.http_log_debug:
             return
 
         string_parts = ['curl -i']
         for element in args:
-            if element in ('GET', 'POST'):
+            if element in ('GET', 'POST', 'DELETE', 'PUT'):
                 string_parts.append(' -X %s' % element)
             else:
                 string_parts.append(' %s' % element)
@@ -86,10 +86,14 @@ class HTTPClient(httplib2.Http):
             header = ' -H "%s: %s"' % (element, kwargs['headers'][element])
             string_parts.append(header)
 
-        self._logger.debug("REQ: %s\n" % "".join(string_parts))
         if 'body' in kwargs:
-            self._logger.debug("REQ BODY: %s\n" % (kwargs['body']))
-        self._logger.debug("RESP:%s %s\n", resp, body)
+            string_parts.append(" -d '%s'" % (kwargs['body']))
+        self._logger.debug("\nREQ: %s\n" % "".join(string_parts))
+
+    def http_log_resp(self, resp, body):
+        if not self.http_log_debug:
+            return
+        self._logger.debug("RESP: %s\nRESP BODY: %s\n", resp, body)
 
     def request(self, *args, **kwargs):
         kwargs.setdefault('headers', kwargs.get('headers', {}))
@@ -99,9 +103,9 @@ class HTTPClient(httplib2.Http):
             kwargs['headers']['Content-Type'] = 'application/json'
             kwargs['body'] = json.dumps(kwargs['body'])
 
+        self.http_log_req(args, kwargs)
         resp, body = super(HTTPClient, self).request(*args, **kwargs)
-
-        self.http_log(args, kwargs, resp, body)
+        self.http_log_resp(resp, body)
 
         if body:
             try: