mirror of
https://github.com/element-hq/synapse
synced 2024-09-19 05:55:14 +00:00
WIP
This commit is contained in:
parent
e75de1d7a6
commit
47f157b510
1 changed files with 4 additions and 5 deletions
|
@ -665,14 +665,13 @@ class PreserveLoggingContext:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
_CURRENT_CONTEXT_VAR: ContextVar[LoggingContextOrSentinel] = ContextVar(
|
_thread_local = threading.local()
|
||||||
"current_context", default=SENTINEL_CONTEXT
|
_thread_local.current_context = SENTINEL_CONTEXT
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def current_context() -> LoggingContextOrSentinel:
|
def current_context() -> LoggingContextOrSentinel:
|
||||||
"""Get the current logging context from thread local storage"""
|
"""Get the current logging context from thread local storage"""
|
||||||
return _CURRENT_CONTEXT_VAR.get()
|
return getattr(_thread_local, "current_context", SENTINEL_CONTEXT)
|
||||||
|
|
||||||
|
|
||||||
def set_current_context(context: LoggingContextOrSentinel) -> LoggingContextOrSentinel:
|
def set_current_context(context: LoggingContextOrSentinel) -> LoggingContextOrSentinel:
|
||||||
|
@ -693,7 +692,7 @@ def set_current_context(context: LoggingContextOrSentinel) -> LoggingContextOrSe
|
||||||
if current is not context:
|
if current is not context:
|
||||||
rusage = get_thread_resource_usage()
|
rusage = get_thread_resource_usage()
|
||||||
current.stop(rusage)
|
current.stop(rusage)
|
||||||
_CURRENT_CONTEXT_VAR.set(context)
|
_thread_local.current_context = context
|
||||||
context.start(rusage)
|
context.start(rusage)
|
||||||
|
|
||||||
return current
|
return current
|
||||||
|
|
Loading…
Reference in a new issue