diff options
author | Mark Haines <mark.haines@matrix.org> | 2014-11-19 16:37:43 +0000 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2014-11-19 16:37:43 +0000 |
commit | 97c7c34f6f71238dcb364374733c1f2200d6b982 (patch) | |
tree | 944a2d841a5eae9fac1baff9fc5e0c504a3f7cb0 /synapse/util | |
parent | SYN-141: Encode query params as UTF-8. (diff) | |
download | synapse-97c7c34f6f71238dcb364374733c1f2200d6b982.tar.xz |
Preserve logging context in a few more places, drop the logging context after it has been stashed to reduce potential for confusion
Diffstat (limited to 'synapse/util')
-rw-r--r-- | synapse/util/__init__.py | 7 | ||||
-rw-r--r-- | synapse/util/logcontext.py | 4 |
2 files changed, 10 insertions, 1 deletions
diff --git a/synapse/util/__init__.py b/synapse/util/__init__.py index c9a73b0413..9ad613b8f1 100644 --- a/synapse/util/__init__.py +++ b/synapse/util/__init__.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from synapse.util.logcontext import LoggingContext from twisted.internet import reactor @@ -35,7 +36,11 @@ class Clock(object): return self.time() * 1000 def call_later(self, delay, callback): - return reactor.callLater(delay, callback) + current_context = LoggingContext.current_context() + def wrapped_callback(): + current_context.thread_local.current_context = current_context + callback() + return reactor.callLater(delay, wrapped_callback) def cancel_call_later(self, timer): timer.cancel() diff --git a/synapse/util/logcontext.py b/synapse/util/logcontext.py index 13176b05ce..2f430a0f19 100644 --- a/synapse/util/logcontext.py +++ b/synapse/util/logcontext.py @@ -18,6 +18,9 @@ class LoggingContext(object): __slots__ = [] + def __str__(self): + return "sentinel" + def copy_to(self, record): pass @@ -102,6 +105,7 @@ class PreserveLoggingContext(object): def __enter__(self): """Captures the current logging context""" self.current_context = LoggingContext.current_context() + LoggingContext.thread_local.current_context = LoggingContext.sentinel def __exit__(self, type, value, traceback): """Restores the current logging context""" |