From 88739cbbf4c86d5aa487f33919765f7e45d1d1cd Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 16 Jul 2026 15:30:47 +0000 Subject: [PATCH] Document the pyo3-log level cache in the logcontext debugging docs Enabling synapse.logging.context.debug at runtime (e.g. from the manhole) silently misses the Rust-emitted enter/exit traces because pyo3-log caches logger levels; the cache is only flushed when the logging config is (re)loaded. Spell out the reset_logging_config() step. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01JFbRtswu7rsHrttJFauUUb --- docs/log_contexts.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/log_contexts.md b/docs/log_contexts.md index fa99e3de64..c5258c29ef 100644 --- a/docs/log_contexts.md +++ b/docs/log_contexts.md @@ -592,3 +592,18 @@ loggers: synapse.logging.context.debug: level: DEBUG ``` + +Note that some of these traces (`LoggingContext(...).__enter__`/`__exit__`) are +emitted from Rust via `pyo3-log`, which caches logger levels for performance. +Configuring the logger in the logging config (as above) works — the cache is +flushed whenever the config is (re)loaded, including on `SIGHUP` — but enabling +the logger *at runtime* (e.g. `setLevel(logging.DEBUG)` from the manhole) will +not surface the Rust-emitted traces until you also flush the cache: + +```python +import logging +from synapse.synapse_rust import reset_logging_config + +logging.getLogger("synapse.logging.context.debug").setLevel(logging.DEBUG) +reset_logging_config() +```