Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Unignore assigning to LogRecord attributes
Browse files Browse the repository at this point in the history
Presumably python/typeshed#8064 makes this ok
  • Loading branch information
David Robertson committed Aug 12, 2022
1 parent 2009bc2 commit 67c737d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions synapse/logging/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,29 +586,29 @@ def filter(self, record: logging.LogRecord) -> Literal[True]:
True to include the record in the log output.
"""
context = current_context()
record.request = self._default_request # type: ignore
record.request = self._default_request

# context should never be None, but if it somehow ends up being, then
# we end up in a death spiral of infinite loops, so let's check, for
# robustness' sake.
if context is not None:
# Logging is interested in the request ID. Note that for backwards
# compatibility this is stored as the "request" on the record.
record.request = str(context) # type: ignore
record.request = str(context)

# Add some data from the HTTP request.
request = context.request
if request is None:
return True

record.ip_address = request.ip_address # type: ignore
record.site_tag = request.site_tag # type: ignore
record.requester = request.requester # type: ignore
record.authenticated_entity = request.authenticated_entity # type: ignore
record.method = request.method # type: ignore
record.url = request.url # type: ignore
record.protocol = request.protocol # type: ignore
record.user_agent = request.user_agent # type: ignore
record.ip_address = request.ip_address
record.site_tag = request.site_tag
record.requester = request.requester
record.authenticated_entity = request.authenticated_entity
record.method = request.method
record.url = request.url
record.protocol = request.protocol
record.user_agent = request.user_agent

return True

Expand Down

0 comments on commit 67c737d

Please sign in to comment.