mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-03 22:44:49 -04:00
Move logging utilities out of the side drawer of util/ and into logging/ (#5606)
This commit is contained in:
parent
cb8d568cf9
commit
463b072b12
98 changed files with 249 additions and 233 deletions
|
@ -1,8 +1,14 @@
|
|||
import twisted.python.failure
|
||||
from twisted.internet import defer, reactor
|
||||
|
||||
from synapse.util import Clock, logcontext
|
||||
from synapse.util.logcontext import LoggingContext
|
||||
from synapse.logging.context import (
|
||||
LoggingContext,
|
||||
PreserveLoggingContext,
|
||||
make_deferred_yieldable,
|
||||
nested_logging_context,
|
||||
run_in_background,
|
||||
)
|
||||
from synapse.util import Clock
|
||||
|
||||
from .. import unittest
|
||||
|
||||
|
@ -43,7 +49,7 @@ class LoggingContextTestCase(unittest.TestCase):
|
|||
context_one.request = "one"
|
||||
|
||||
# fire off function, but don't wait on it.
|
||||
d2 = logcontext.run_in_background(function)
|
||||
d2 = run_in_background(function)
|
||||
|
||||
def cb(res):
|
||||
callback_completed[0] = True
|
||||
|
@ -85,7 +91,7 @@ class LoggingContextTestCase(unittest.TestCase):
|
|||
def test_run_in_background_with_non_blocking_fn(self):
|
||||
@defer.inlineCallbacks
|
||||
def nonblocking_function():
|
||||
with logcontext.PreserveLoggingContext():
|
||||
with PreserveLoggingContext():
|
||||
yield defer.succeed(None)
|
||||
|
||||
return self._test_run_in_background(nonblocking_function)
|
||||
|
@ -94,7 +100,7 @@ class LoggingContextTestCase(unittest.TestCase):
|
|||
# a function which returns a deferred which looks like it has been
|
||||
# called, but is actually paused
|
||||
def testfunc():
|
||||
return logcontext.make_deferred_yieldable(_chained_deferred_function())
|
||||
return make_deferred_yieldable(_chained_deferred_function())
|
||||
|
||||
return self._test_run_in_background(testfunc)
|
||||
|
||||
|
@ -128,7 +134,7 @@ class LoggingContextTestCase(unittest.TestCase):
|
|||
with LoggingContext() as context_one:
|
||||
context_one.request = "one"
|
||||
|
||||
d1 = logcontext.make_deferred_yieldable(blocking_function())
|
||||
d1 = make_deferred_yieldable(blocking_function())
|
||||
# make sure that the context was reset by make_deferred_yieldable
|
||||
self.assertIs(LoggingContext.current_context(), sentinel_context)
|
||||
|
||||
|
@ -144,7 +150,7 @@ class LoggingContextTestCase(unittest.TestCase):
|
|||
with LoggingContext() as context_one:
|
||||
context_one.request = "one"
|
||||
|
||||
d1 = logcontext.make_deferred_yieldable(_chained_deferred_function())
|
||||
d1 = make_deferred_yieldable(_chained_deferred_function())
|
||||
# make sure that the context was reset by make_deferred_yieldable
|
||||
self.assertIs(LoggingContext.current_context(), sentinel_context)
|
||||
|
||||
|
@ -161,7 +167,7 @@ class LoggingContextTestCase(unittest.TestCase):
|
|||
with LoggingContext() as context_one:
|
||||
context_one.request = "one"
|
||||
|
||||
d1 = logcontext.make_deferred_yieldable("bum")
|
||||
d1 = make_deferred_yieldable("bum")
|
||||
self._check_test_key("one")
|
||||
|
||||
r = yield d1
|
||||
|
@ -170,7 +176,7 @@ class LoggingContextTestCase(unittest.TestCase):
|
|||
|
||||
def test_nested_logging_context(self):
|
||||
with LoggingContext(request="foo"):
|
||||
nested_context = logcontext.nested_logging_context(suffix="bar")
|
||||
nested_context = nested_logging_context(suffix="bar")
|
||||
self.assertEqual(nested_context.request, "foo-bar")
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue