Handle log message interpolation by the logger

According to OpenStack Guideline[1], logged string message should be
interpolated by the logger.

[1]: http://docs.openstack.org/developer/oslo.i18n/guidelines.html#adding-variables-to-log-messages
Closes-Bug: #1596829

Change-Id: I0c4a2a1cce98dbf78dd30850951466cd01491cfc
This commit is contained in:
Gábor Antal 2017-02-07 17:32:27 +01:00
parent 56776ce009
commit 8d67ca5cf4
2 changed files with 6 additions and 6 deletions

View File

@ -113,9 +113,9 @@ class HTTPClient(object):
header = "-H '%s: %s'" % (element, kwargs['headers'][element]) header = "-H '%s: %s'" % (element, kwargs['headers'][element])
string_parts.append(header) string_parts.append(header)
_logger.debug("REQ: %s" % " ".join(string_parts)) _logger.debug("REQ: %s", " ".join(string_parts))
if 'data' in kwargs: if 'data' in kwargs:
_logger.debug("REQ BODY: %s\n" % (kwargs['data'])) _logger.debug("REQ BODY: %s\n", (kwargs['data']))
def _http_log_resp(self, resp): def _http_log_resp(self, resp):
if not self.debug: if not self.debug:

View File

@ -148,11 +148,11 @@ class HTTPClient(object):
if attempts > self.retries: if attempts > self.retries:
raise raise
self._logger.debug("Request error: %s" % six.text_type(e)) self._logger.debug("Request error: %s", six.text_type(e))
self._logger.debug( self._logger.debug(
"Failed attempt(%(current)s of %(total)s), " "Failed attempt(%(current)s of %(total)s), "
" retrying in %(sec)s seconds" % { " retrying in %(sec)s seconds", {
'current': attempts, 'current': attempts,
'total': self.retries, 'total': self.retries,
'sec': timeout 'sec': timeout
@ -189,13 +189,13 @@ class HTTPClient(object):
if "password" in data: if "password" in data:
data = strutils.mask_password(data) data = strutils.mask_password(data)
string_parts.append(" -d '%s'" % data) string_parts.append(" -d '%s'" % data)
self._logger.debug("\nREQ: %s\n" % "".join(string_parts)) self._logger.debug("\nREQ: %s\n", "".join(string_parts))
def log_response(self, resp): def log_response(self, resp):
if not self.http_log_debug: if not self.http_log_debug:
return return
self._logger.debug( self._logger.debug(
"RESP: [%(code)s] %(headers)s\nRESP BODY: %(body)s\n" % { "RESP: [%(code)s] %(headers)s\nRESP BODY: %(body)s\n", {
'code': resp.status_code, 'code': resp.status_code,
'headers': resp.headers, 'headers': resp.headers,
'body': resp.text 'body': resp.text