mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-08-01 14:13:01 +02:00
Don't prefix command output (like Borg output) with the global log prefix (#635).
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user