2
0
Эх сурвалжийг харах

teardown logging in exec_cmd

for normal borg command invocation:
- logging is set up in Archiver.run
- the atexit handler calls logging.shutdown when process terminates

for tests:
- Archiver.run called by exec_cmd
- no atexit handler executed as process lives on
- borg.logger.teardown (calls shutdown and configured=False) now
  called in exec_cmd
Thomas Waldmann 2 жил өмнө
parent
commit
746cef1cba

+ 7 - 0
src/borg/logger.py

@@ -106,10 +106,17 @@ def _log_warning(message, category, filename, lineno, file=None, line=None):
 
 
 def remove_handlers(logger):
 def remove_handlers(logger):
     for handler in logger.handlers[:]:
     for handler in logger.handlers[:]:
+        handler.flush()
         handler.close()
         handler.close()
         logger.removeHandler(handler)
         logger.removeHandler(handler)
 
 
 
 
+def teardown_logging():
+    global configured
+    logging.shutdown()
+    configured = False
+
+
 def setup_logging(stream=None, conf_fname=None, env_var="BORG_LOGGING_CONF", level="info", is_serve=False, json=False):
 def setup_logging(stream=None, conf_fname=None, env_var="BORG_LOGGING_CONF", level="info", is_serve=False, json=False):
     """setup logging module according to the arguments provided
     """setup logging module according to the arguments provided
 
 

+ 5 - 1
src/borg/testsuite/archiver/__init__.py

@@ -21,6 +21,7 @@ from ...constants import *  # NOQA
 from ...helpers import Location
 from ...helpers import Location
 from ...helpers import EXIT_SUCCESS
 from ...helpers import EXIT_SUCCESS
 from ...helpers import bin_to_hex
 from ...helpers import bin_to_hex
+from ...logger import teardown_logging
 from ...manifest import Manifest
 from ...manifest import Manifest
 from ...remote import RemoteRepository
 from ...remote import RemoteRepository
 from ...repository import Repository
 from ...repository import Repository
@@ -81,7 +82,10 @@ def exec_cmd(*args, archiver=None, fork=False, exe=None, input=b"", binary_outpu
             except SystemExit as e:
             except SystemExit as e:
                 output_text.flush()
                 output_text.flush()
                 return e.code, output.getvalue() if binary_output else output.getvalue().decode()
                 return e.code, output.getvalue() if binary_output else output.getvalue().decode()
-            ret = archiver.run(args)
+            try:
+                ret = archiver.run(args)
+            finally:
+                teardown_logging()  # usually done via atexit, but we do not exit here
             output_text.flush()
             output_text.flush()
             return ret, output.getvalue() if binary_output else output.getvalue().decode()
             return ret, output.getvalue() if binary_output else output.getvalue().decode()
         finally:
         finally: