proxy-logging: Allow to add domain in log messages
Change-Id: Id441688aac1088041e243b8ee70710d9c5d7911b
This commit is contained in:
parent
26b2425ab8
commit
1831658b33
@ -59,6 +59,7 @@ remote_addr The IP address of the other end of the TCP connection.
|
||||
(anonymizable)
|
||||
end_time Timestamp of the request. (timestamp)
|
||||
method The HTTP verb in the request.
|
||||
domain The domain in the request. (anonymizable)
|
||||
path The path portion of the request. (anonymizable)
|
||||
protocol The transport protocol used (currently one of http or
|
||||
https).
|
||||
|
@ -151,6 +151,8 @@ class ProxyLoggingMiddleware(object):
|
||||
self.anonymization_salt),
|
||||
'remote_addr': StrAnonymizer('4.3.2.1', self.anonymization_method,
|
||||
self.anonymization_salt),
|
||||
'domain': StrAnonymizer('', self.anonymization_method,
|
||||
self.anonymization_salt),
|
||||
'path': StrAnonymizer('/', self.anonymization_method,
|
||||
self.anonymization_salt),
|
||||
'referer': StrAnonymizer('ref', self.anonymization_method,
|
||||
@ -236,6 +238,10 @@ class ProxyLoggingMiddleware(object):
|
||||
:param wire_status_int: the on the wire status int
|
||||
"""
|
||||
self.obscure_req(req)
|
||||
domain = req.environ.get('HTTP_HOST',
|
||||
req.environ.get('SERVER_NAME', None))
|
||||
if ':' in domain:
|
||||
domain, port = domain.rsplit(':', 1)
|
||||
resp_headers = resp_headers or {}
|
||||
logged_headers = None
|
||||
if self.log_hdrs:
|
||||
@ -267,6 +273,8 @@ class ProxyLoggingMiddleware(object):
|
||||
'remote_addr': StrAnonymizer(req.remote_addr,
|
||||
self.anonymization_method,
|
||||
self.anonymization_salt),
|
||||
'domain': StrAnonymizer(domain, self.anonymization_method,
|
||||
self.anonymization_salt),
|
||||
'path': StrAnonymizer(req.path_qs, self.anonymization_method,
|
||||
self.anonymization_salt),
|
||||
'referer': StrAnonymizer(req.referer, self.anonymization_method,
|
||||
|
@ -423,9 +423,10 @@ class TestProxyLogging(unittest.TestCase):
|
||||
'template which can be edited in config: '
|
||||
'{protocol} {path} {method} '
|
||||
'{path.anonymized} {container.anonymized} '
|
||||
'{request_time} {start_time.datetime} {end_time} {ttfb}')})
|
||||
'{request_time} {start_time.datetime} {end_time} {ttfb} '
|
||||
'{domain}')})
|
||||
app.access_logger = debug_logger()
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
||||
req = Request.blank('/', headers={'Host': 'example.com'})
|
||||
with mock.patch('time.time',
|
||||
mock.MagicMock(
|
||||
side_effect=[10000000.0, 10000000.5, 10000001.0])):
|
||||
@ -443,6 +444,7 @@ class TestProxyLogging(unittest.TestCase):
|
||||
self.assertEqual(log_parts[13], '26/Apr/1970/17/46/40')
|
||||
self.assertEqual(log_parts[14], '10000001.000000000')
|
||||
self.assertEqual(log_parts[15], '0.5')
|
||||
self.assertEqual(log_parts[16], 'example.com')
|
||||
self.assertEqual(resp_body, b'FAKE APP')
|
||||
|
||||
def test_log_msg_template_s3api(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user