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

Don't prefix command output (like Borg output) with the global log prefix (#635).

Dan Helfman 4 сар өмнө
parent
commit
b9ec9bb873

+ 1 - 1
borgmatic/borg/list.py

@@ -237,7 +237,7 @@ def list_archive(
 
     # For each archive listed by Borg, run list on the contents of that archive.
     for archive in archive_lines:
-        logger.answer(f'{repository_path}: Listing archive {archive}')
+        logger.answer(f'Listing archive {archive}')
 
         archive_arguments = copy.copy(list_arguments)
         archive_arguments.archive = archive

+ 1 - 1
borgmatic/borg/repo_list.py

@@ -59,7 +59,7 @@ def resolve_archive_name(
     except IndexError:
         raise ValueError('No archives found in the repository')
 
-    logger.debug(f'{repository_path}: Latest archive is {latest_archive}')
+    logger.debug(f'Latest archive is {latest_archive}')
 
     return latest_archive
 

+ 14 - 7
borgmatic/execute.py

@@ -6,6 +6,8 @@ import select
 import subprocess
 import textwrap
 
+import borgmatic.logger
+
 logger = logging.getLogger(__name__)
 
 
@@ -309,13 +311,18 @@ def execute_command(
     if not run_to_completion:
         return process
 
-    log_outputs(
-        (process,),
-        (input_file, output_file),
-        output_log_level,
-        borg_local_path,
-        borg_exit_codes,
-    )
+    try:
+        original_log_prefix = borgmatic.logger.get_log_prefix()
+        borgmatic.logger.set_log_prefix(None)  # Log command output without any prefix.
+        log_outputs(
+            (process,),
+            (input_file, output_file),
+            output_log_level,
+            borg_local_path,
+            borg_exit_codes,
+        )
+    finally:
+        borgmatic.logger.set_log_prefix(original_log_prefix)
 
 
 def execute_command_and_capture_output(

+ 14 - 0
borgmatic/logger.py

@@ -186,6 +186,20 @@ def add_custom_log_levels():  # pragma: no cover
     add_logging_level('DISABLED', DISABLED)
 
 
+def get_log_prefix():
+    '''
+    Return the log prefix (as set with set_log_prefix()) for the first log handler. If there is no
+    such prefix, return None.
+    '''
+    for handler in logging.getLogger().handlers:
+        defaults = handler.formatter._style._defaults
+
+        if not defaults:
+            return None
+
+        return defaults.get('prefix').rstrip().rstrip(':')
+
+
 def set_log_prefix(prefix):
     '''
     Given a prefix string, set it onto the formatter defaults for every logging handler so that it