in python/website/research_pacs/website/log.py [0:0]
def log_http_request(self, response):
"""
Log a HTTP request to the access log file.
Args:
response: Flask Response object
"""
try:
# The request is logged unless the request path starts with one of the excluded prefixes or
# ends with one of the excluded suffixes
for prefix in self._excluded_prefixes.split(','):
if request.path.startswith(prefix):
return
for suffix in self._excluded_suffixes.split(','):
if request.path.endswith(suffix):
return
log_msg = {
'Type': 'HttpRequest',
'User': {
'IpAddress': request.headers['X-Forwarded-For'] if 'X-Forwarded-For' in request.headers else request.remote_addr,
'UserAgent': request.user_agent.string
},
'Request': {
'Method': request.method,
'Path': request.path,
'QueryString': request.query_string.decode(),
'RequestTime': datetime.now().isoformat()
},
'Response': {
'StatusCode': response.status_code,
'ContentType': response.content_type,
'ContentLength': response.content_length,
'ResponseTime': datetime.now().isoformat()
}
}
self._log_request(log_msg)
except:
logger.warning('Failed to log an HTTP request')