From 7ed71490ef236e6241725362826e181591f86102 Mon Sep 17 00:00:00 2001 From: Goutham Pacha Ravi Date: Fri, 15 Feb 2019 11:58:28 -0800 Subject: [PATCH] Fix logging in wsgi module - Method names in the wsgi module are being logged incorrectly, like "Calling method ". - The body attribute needs to be decoded when logging. - HTTP Status codes can be passed as strings. TrivialFix Change-Id: I423de87cf09caa522817a9b949dbf448be833587 --- manila/api/openstack/wsgi.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/manila/api/openstack/wsgi.py b/manila/api/openstack/wsgi.py index 27f9d6b6e7..d1c3933b8d 100644 --- a/manila/api/openstack/wsgi.py +++ b/manila/api/openstack/wsgi.py @@ -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