Преглед изворни кода

Show summary log errors regardless of verbosity. Log the "summary:" header with level based on the contained logs.

Dan Helfman пре 5 година
родитељ
комит
f4a231420f
4 измењених фајлова са 23 додато и 15 уклоњено
  1. 4 0
      NEWS
  2. 14 14
      borgmatic/commands/borgmatic.py
  3. 1 1
      setup.py
  4. 4 0
      tests/unit/commands/test_borgmatic.py

+ 4 - 0
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.

+ 14 - 14
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,
+        )
+
+    for log in summary_logs:
+        logger.handle(log)
 
-    if any(log.levelno == logging.CRITICAL for log in summary_logs):
+    if summary_logs_max_level >= logging.CRITICAL:
         exit_with_help_link()

+ 1 - 1
setup.py

@@ -1,6 +1,6 @@
 from setuptools import find_packages, setup
 
-VERSION = '1.4.13'
+VERSION = '1.4.14'
 
 
 setup(

+ 4 - 0
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)