From 9f5c6f6bc7203a69d1313f0b4c1870066581408b Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Mon, 4 May 2020 10:56:58 -0400 Subject: [PATCH 1/3] Update use of Synapse's logging context. --- .gitignore | 3 +++ s3_storage_provider.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9624757..bb622f6 100644 --- a/.gitignore +++ b/.gitignore @@ -103,3 +103,6 @@ ENV/ # Temp files *~ _trial* + +# PyCharm project settings +.idea diff --git a/s3_storage_provider.py b/s3_storage_provider.py index a6951a1..7576fe5 100644 --- a/s3_storage_provider.py +++ b/s3_storage_provider.py @@ -26,9 +26,13 @@ from twisted.python.failure import Failure from twisted.python.threadpool import ThreadPool +from synapse.logging.context import ( + current_context, + LoggingContext, + make_deferred_yieldable, +) from synapse.rest.media.v1._base import Responder from synapse.rest.media.v1.storage_provider import StorageProvider -from synapse.util.logcontext import LoggingContext, make_deferred_yieldable logger = logging.getLogger("synapse.s3") @@ -93,7 +97,7 @@ def _store_file(): def fetch(self, path, file_info): """See StorageProvider.fetch""" - logcontext = LoggingContext.current_context() + logcontext = current_context() d = defer.Deferred() self._download_pool.callInThread( From 8db49ed5d9a5c76d5b84daa98df72ac1952527d0 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Mon, 4 May 2020 11:56:32 -0400 Subject: [PATCH 2/3] Backwards compatibility. --- s3_storage_provider.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/s3_storage_provider.py b/s3_storage_provider.py index 7576fe5..276c0f9 100644 --- a/s3_storage_provider.py +++ b/s3_storage_provider.py @@ -27,13 +27,18 @@ from twisted.python.threadpool import ThreadPool from synapse.logging.context import ( - current_context, LoggingContext, make_deferred_yieldable, ) from synapse.rest.media.v1._base import Responder from synapse.rest.media.v1.storage_provider import StorageProvider +# Synapse 1.13.0 moved current_context to a module-level function. +try: + from synapse.logging.context import current_context +except ImportError: + current_context = LoggingContext.current_context + logger = logging.getLogger("synapse.s3") From 03af4d3702ef47f7312dcc96425824a877d56129 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Mon, 4 May 2020 12:03:12 -0400 Subject: [PATCH 3/3] isort --- s3_storage_provider.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/s3_storage_provider.py b/s3_storage_provider.py index 276c0f9..3f399f7 100644 --- a/s3_storage_provider.py +++ b/s3_storage_provider.py @@ -26,10 +26,7 @@ from twisted.python.failure import Failure from twisted.python.threadpool import ThreadPool -from synapse.logging.context import ( - LoggingContext, - make_deferred_yieldable, -) +from synapse.logging.context import LoggingContext, make_deferred_yieldable from synapse.rest.media.v1._base import Responder from synapse.rest.media.v1.storage_provider import StorageProvider