Skip to content

Update web log context fields to match proxy log context fields #861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proxy/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _env_threadless_compliant() -> bool:
DEFAULT_LOG_FILE = None
DEFAULT_LOG_FORMAT = '%(asctime)s - pid:%(process)d [%(levelname)-.1s] %(module)s.%(funcName)s:%(lineno)d - %(message)s'
DEFAULT_LOG_LEVEL = 'INFO'
DEFAULT_WEB_ACCESS_LOG_FORMAT = '{client_addr} - {request_method} {request_path} - {connection_time_ms}ms'
DEFAULT_WEB_ACCESS_LOG_FORMAT = '{client_ip}:{client_port} - {request_method} {request_path} - {connection_time_ms}ms'
DEFAULT_HTTP_ACCESS_LOG_FORMAT = '{client_ip}:{client_port} - ' + \
'{request_method} {server_host}:{server_port}{request_path} - ' + \
'{response_code} {response_reason} - {response_bytes} bytes - ' + \
Expand Down
2 changes: 0 additions & 2 deletions proxy/http/proxy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,9 @@ def on_client_connection_close(self) -> None:
'request_method': text_(self.request.method),
'request_path': text_(self.request.path),
'request_bytes': self.request.total_size,
'request_code': self.request.code,
'request_ua': self.request.header(b'user-agent')
if self.request.has_header(b'user-agent')
else None,
'request_reason': self.request.reason,
'request_version': self.request.version,
# Response
'response_bytes': self.response.total_size,
Expand Down
22 changes: 20 additions & 2 deletions proxy/http/server/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,28 @@ def on_client_connection_close(self) -> None:
if self.request.has_host():
return
context = {
'client_addr': self.client.address,
'client_ip': None if not self.client.addr else self.client.addr[0],
'client_port': None if not self.client.addr else self.client.addr[1],
'connection_time_ms': '%.2f' % ((time.time() - self.start_time) * 1000),
# Request
'request_method': text_(self.request.method),
'request_path': text_(self.request.path),
'connection_time_ms': '%.2f' % ((time.time() - self.start_time) * 1000),
'request_bytes': self.request.total_size,
'request_ua': self.request.header(b'user-agent')
if self.request.has_header(b'user-agent')
else None,
'request_version': self.request.version,
# Response
#
# TODO: Track and inject web server specific response attributes
# Currently, plugins are allowed to queue raw bytes, because of
# which we'll have to reparse the queued packets to deduce
# several attributes required below. At least for code and
# reason attributes.
#
# 'response_bytes': self.response.total_size,
# 'response_code': text_(self.response.code),
# 'response_reason': text_(self.response.reason),
}
log_handled = False
if self.route:
Expand Down