mirror of
https://github.com/element-hq/synapse.git
synced 2026-10-15 04:31:13 +00:00
Restore printing sentinel for log_record.request (#19172)
This was unintentionally changed in https://github.com/element-hq/synapse/pull/19068. There is no real bug here. Without this PR, we just printed an empty string for the `sentinel` logcontext whereas the prior art behavior was to print `sentinel` which this PR restores. Found while staring at the logs in https://github.com/element-hq/synapse/issues/19165 ### Reproduction strategy 1. Configure Synapse with [logging](https://github.com/element-hq/synapse/blob/df802882bb2ec7d52d5c064c20531fe5a5b263b1/docs/sample_log_config.yaml) 1. Start Synapse: `poetry run synapse_homeserver --config-path homeserver.yaml` 1. Notice the `asyncio - 64 - DEBUG - - Using selector: EpollSelector` log line (notice empty string `- -`) 1. With this PR, the log line will be `asyncio - 64 - DEBUG - sentinel - Using selector: EpollSelector` (notice `sentinel`)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Restore printing `sentinel` for the log record `request` when no logcontext is active.
|
||||
+17
-12
@@ -619,19 +619,24 @@ class LoggingContextFilter(logging.Filter):
|
||||
True to include the record in the log output.
|
||||
"""
|
||||
context = current_context()
|
||||
record.request = self._default_request
|
||||
|
||||
# Avoid overwriting an existing `server_name` on the record. This is running in
|
||||
# the context of a global log record filter so there may be 3rd-party code that
|
||||
# adds their own `server_name` and we don't want to interfere with that
|
||||
# (clobber).
|
||||
if not hasattr(record, "server_name"):
|
||||
record.server_name = "unknown_server_from_no_logcontext"
|
||||
|
||||
# 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
|
||||
# type-ignore: `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:
|
||||
#
|
||||
# Add some default values to avoid log formatting errors.
|
||||
if context is None:
|
||||
record.request = self._default_request # type: ignore[unreachable]
|
||||
|
||||
# Avoid overwriting an existing `server_name` on the record. This is running in
|
||||
# the context of a global log record filter so there may be 3rd-party code that
|
||||
# adds their own `server_name` and we don't want to interfere with that
|
||||
# (clobber).
|
||||
if not hasattr(record, "server_name"):
|
||||
record.server_name = "unknown_server_from_no_logcontext"
|
||||
|
||||
# Otherwise, in the normal, expected case, fill in the log record attributes
|
||||
# from the logcontext.
|
||||
else:
|
||||
|
||||
def safe_set(attr: str, value: Any) -> None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user