Don't log whole API responses under INFO log level - always log them
under DEBUG.
@@ -73,13 +73,13 @@ class LoggingMiddleware(object):
except NotFoundException:
endpoint = {}
- log_result = endpoint.get('x-log-result', True)
-
if isinstance(retval, types.GeneratorType):
content_length = [float('inf')]
log_result = False
+ else:
+ log_result = True
- # Log the incoming request
+ # Log the response
values = {
'method': request.method,
'path': request.path,
@@ -90,13 +90,13 @@ class LoggingMiddleware(object):
'request_id': request.headers.get(REQUEST_ID_HEADER, None)
}
- if log_result:
- values['result'] = retval[0]
- log_msg = '%(request_id)s - %(status)s %(content_length)s %(runtime)sms\n%(result)s'\
- % values
- else:
- log_msg = '%(request_id)s - %(status)s %(content_length)s %(runtime)sms' % values
+ controller_result = retval[0]
+
+ log_msg = '%(request_id)s - %(status)s %(content_length)s %(runtime)sms' % (values)
LOG.info(log_msg, extra=values)
+ if log_result:
+ LOG.debug(controller_result, extra=values)
+
return retval
