summary refs log tree commit diff
path: root/synapse/logging/context.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2020-05-05 18:14:00 +0100
committerRichard van der Hoff <richard@matrix.org>2020-05-05 18:14:00 +0100
commit13dd458b8ddb248a84f5cf0c063e6002c831d72a (patch)
treec29b804da054820a6c0ed1d59d0159e620862093 /synapse/logging/context.py
parentUpdate changelog.d/7423.misc (diff)
parentAdd backwards compatibility codepath to LoggingContext. (#7408) (diff)
downloadsynapse-13dd458b8ddb248a84f5cf0c063e6002c831d72a.tar.xz
Merge branch 'release-v1.13.0' into erikj/faster_device_lists_fetch
Diffstat (limited to 'synapse/logging/context.py')
-rw-r--r--synapse/logging/context.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/synapse/logging/context.py b/synapse/logging/context.py
index a8f674d13d..856534e91a 100644
--- a/synapse/logging/context.py
+++ b/synapse/logging/context.py
@@ -27,6 +27,7 @@ import inspect
 import logging
 import threading
 import types
+import warnings
 from typing import TYPE_CHECKING, Optional, Tuple, TypeVar, Union
 
 from typing_extensions import Literal
@@ -287,6 +288,46 @@ class LoggingContext(object):
             return str(self.request)
         return "%s@%x" % (self.name, id(self))
 
+    @classmethod
+    def current_context(cls) -> LoggingContextOrSentinel:
+        """Get the current logging context from thread local storage
+
+        This exists for backwards compatibility. ``current_context()`` should be
+        called directly.
+
+        Returns:
+            LoggingContext: the current logging context
+        """
+        warnings.warn(
+            "synapse.logging.context.LoggingContext.current_context() is deprecated "
+            "in favor of synapse.logging.context.current_context().",
+            DeprecationWarning,
+            stacklevel=2,
+        )
+        return current_context()
+
+    @classmethod
+    def set_current_context(
+        cls, context: LoggingContextOrSentinel
+    ) -> LoggingContextOrSentinel:
+        """Set the current logging context in thread local storage
+
+        This exists for backwards compatibility. ``set_current_context()`` should be
+        called directly.
+
+        Args:
+            context(LoggingContext): The context to activate.
+        Returns:
+            The context that was previously active
+        """
+        warnings.warn(
+            "synapse.logging.context.LoggingContext.set_current_context() is deprecated "
+            "in favor of synapse.logging.context.set_current_context().",
+            DeprecationWarning,
+            stacklevel=2,
+        )
+        return set_current_context(context)
+
     def __enter__(self) -> "LoggingContext":
         """Enters this logging context into thread local storage"""
         old_context = set_current_context(self)