File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -353,14 +353,19 @@ class LoggerContext(Generic[THandler], ABC):
353353
354354 def __init__ (self , enabled = True ):
355355 """
356- :param enabled: whether to actually perform any logging .
357- This switch allows the with statement to be applied regardless of whether logging shall be enabled.
356+ :param enabled: whether to actually enable the context, applying the new log handler .
357+ This switch allows the with statement to be applied regardless of whether the context shall be enabled.
358358 """
359359 self .enabled = enabled
360360 self ._log_handler = None
361361
362362 @abstractmethod
363363 def _create_log_handler (self ) -> THandler :
364+ """
365+ Creates and registers/enables the log handler to be used within the context.
366+
367+ :return: the handler
368+ """
364369 pass
365370
366371 def __enter__ (self ) -> Optional [THandler ]:
@@ -369,7 +374,9 @@ def __enter__(self) -> Optional[THandler]:
369374 return self ._log_handler
370375
371376 def __exit__ (self , exc_type , exc_value , traceback ):
372- if self ._log_handler is not None :
377+ if self .enabled :
378+ if exc_type is not None :
379+ log .error (f"Exception within { self .__class__ .__name__ } " , exc_info = exc_value )
373380 remove_log_handler (self ._log_handler )
374381
375382
You can’t perform that action at this time.
0 commit comments