@@ -411,10 +411,13 @@ def __exit__(
411411 current = set_current_context (self .previous_context )
412412 if current is not self :
413413 if current is SENTINEL_CONTEXT :
414- logcontext_error ("Expected logging context %s was lost" % (self ,))
414+ logcontext_error (
415+ "LoggingContext: Expected logging context %s was lost" % (self ,)
416+ )
415417 else :
416418 logcontext_error (
417- "Expected logging context %s but found %s" % (self , current )
419+ "LoggingContext: Expected logging context %s but found %s"
420+ % (self , current )
418421 )
419422
420423 # the fact that we are here suggests that the caller thinks that everything
@@ -636,23 +639,44 @@ def __init__(
636639
637640 def __enter__ (self ) -> None :
638641 self ._old_context = set_current_context (self ._new_context )
642+ import traceback
643+
644+ logger .info (
645+ "asdf PreserveLoggingContext enter new=%s old=%s %s" ,
646+ self ._new_context ,
647+ self ._old_context ,
648+ traceback .format_stack ()[- 2 ].replace (
649+ "/home/eric/Documents/github/element/synapse/" , ""
650+ ),
651+ )
639652
640653 def __exit__ (
641654 self ,
642655 type : Optional [Type [BaseException ]],
643656 value : Optional [BaseException ],
644657 traceback : Optional [TracebackType ],
645658 ) -> None :
659+ import traceback
660+
661+ logger .info (
662+ "asdf PreserveLoggingContext exit new=%s old=%s %s" ,
663+ self ._new_context ,
664+ self ._old_context ,
665+ traceback .format_stack ()[- 2 ].replace (
666+ "/home/eric/Documents/github/element/synapse/" , ""
667+ ),
668+ )
646669 context = set_current_context (self ._old_context )
647670
648671 if context != self ._new_context :
649672 if not context :
650673 logcontext_error (
651- "Expected logging context %s was lost" % (self ._new_context ,)
674+ "PreserveLoggingContext: Expected logging context %s was lost"
675+ % (self ._new_context ,)
652676 )
653677 else :
654678 logcontext_error (
655- "Expected logging context %s but found %s"
679+ "PreserveLoggingContext: Expected logging context %s but found %s"
656680 % (
657681 self ._new_context ,
658682 context ,
@@ -684,6 +708,15 @@ def set_current_context(context: LoggingContextOrSentinel) -> LoggingContextOrSe
684708
685709 current = current_context ()
686710
711+ # import traceback
712+
713+ logger .info (
714+ "asdf set_current_context new=%s old=%s" ,
715+ context ,
716+ current ,
717+ # traceback.format_stack(),
718+ )
719+
687720 if current is not context :
688721 rusage = get_thread_resource_usage ()
689722 current .stop (rusage )
0 commit comments