Fix logging in wsgi module

- Method names in the wsgi module are
  being logged incorrectly, like "Calling method
  <bound method METHODNAME of CLASS object at HEXADDR>".
- The body attribute needs to be decoded when logging.
- HTTP Status codes can be passed as strings.

TrivialFix
Change-Id: I423de87cf09caa522817a9b949dbf448be833587
This commit is contained in:
Goutham Pacha Ravi 2019-02-15 11:58:28 -08:00 committed by Tom Barron
parent d9026c7183
commit 7ed71490ef
1 changed files with 12 additions and 5 deletions

View File

@ -20,6 +20,7 @@ import time
from oslo_log import log
from oslo_serialization import jsonutils
from oslo_utils import encodeutils
from oslo_utils import strutils
import six
from six.moves import http_client
@ -778,15 +779,21 @@ class Resource(wsgi.Application):
msg = _("Malformed request body")
return Fault(webob.exc.HTTPBadRequest(explanation=msg))
try:
method_name = meth.__qualname__
except AttributeError:
method_name = 'Controller: %s Method: %s' % (
six.text_type(self.controller), meth.__name__)
if body:
decoded_body = encodeutils.safe_decode(body, errors='ignore')
msg = ("Action: '%(action)s', calling method: %(meth)s, body: "
"%(body)s") % {'action': action,
'body': six.text_type(body),
'meth': six.text_type(meth)}
'body': decoded_body,
'meth': method_name}
LOG.debug(strutils.mask_password(msg))
else:
LOG.debug("Calling method '%(meth)s'",
{'meth': six.text_type(meth)})
LOG.debug("Calling method '%(meth)s'", {'meth': method_name})
# Now, deserialize the request body...
try:
@ -852,7 +859,7 @@ class Resource(wsgi.Application):
try:
msg_dict = dict(url=request.url, status=response.status_int)
msg = _("%(url)s returned with HTTP %(status)d") % msg_dict
msg = _("%(url)s returned with HTTP %(status)s") % msg_dict
except AttributeError as e:
msg_dict = dict(url=request.url, e=e)
msg = _("%(url)s returned a fault: %(e)s") % msg_dict