From f4a231420f90b9619a84cbb64a93ad290a790d43 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 25 Nov 2019 10:31:09 -0800 Subject: [PATCH] Show summary log errors regardless of verbosity. Log the "summary:" header with level based on the contained logs. --- NEWS | 4 ++++ borgmatic/commands/borgmatic.py | 28 +++++++++++++-------------- setup.py | 2 +- tests/unit/commands/test_borgmatic.py | 4 ++++ 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index 9714af5..26948a5 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +1.4.14 + * Show summary log errors regardless of verbosity level, and log the "summary:" header with a log + level based on the contained summary logs. + 1.4.13 * Show full error logs at "--verbosity 0" so you can see command output without upping the verbosity level. diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 17f95af..44b7128 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -392,11 +392,9 @@ def make_error_log_records(message, error=None): except CalledProcessError as error: yield log_record(levelno=logging.CRITICAL, levelname='CRITICAL', msg=message) if error.output: + # Suppress these logs for now and save full error output for the log summary at the end. yield log_record( - levelno=logging.CRITICAL, - levelname='CRITICAL', - msg=error.output, - suppress_log=bool(logger.getEffectiveLevel() < logging.WARNING), + levelno=logging.CRITICAL, levelname='CRITICAL', msg=error.output, suppress_log=True ) yield log_record(levelno=logging.CRITICAL, levelname='CRITICAL', msg=error) except (ValueError, OSError) as error: @@ -543,16 +541,18 @@ def main(): # pragma: no cover logger.debug('Ensuring legacy configuration is upgraded') convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames) - summary_logs = list(collect_configuration_run_summary_logs(configs, arguments)) + summary_logs = parse_logs + list(collect_configuration_run_summary_logs(configs, arguments)) + summary_logs_max_level = max(log.levelno for log in summary_logs) - if logger.getEffectiveLevel() < logging.WARNING: - logger.info('') - logger.info('summary:') - [ - logger.handle(log) - for log in parse_logs + summary_logs - if log.levelno >= logger.getEffectiveLevel() - ] + for message in ('', 'summary:'): + log_record( + levelno=summary_logs_max_level, + levelname=logging.getLevelName(summary_logs_max_level), + msg=message, + ) - if any(log.levelno == logging.CRITICAL for log in summary_logs): + for log in summary_logs: + logger.handle(log) + + if summary_logs_max_level >= logging.CRITICAL: exit_with_help_link() diff --git a/setup.py b/setup.py index 081d5bf..dfa85e8 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.4.13' +VERSION = '1.4.14' setup( diff --git a/tests/unit/commands/test_borgmatic.py b/tests/unit/commands/test_borgmatic.py index c4e47ff..6b0bd68 100644 --- a/tests/unit/commands/test_borgmatic.py +++ b/tests/unit/commands/test_borgmatic.py @@ -119,6 +119,10 @@ def test_log_record_does_not_raise(): module.log_record(levelno=1, foo='bar', baz='quux') +def test_log_record_with_suppress_does_not_raise(): + module.log_record(levelno=1, foo='bar', baz='quux', suppress_log=True) + + def test_make_error_log_records_generates_output_logs_for_message_only(): flexmock(module).should_receive('log_record').replace_with(dict)