From 55ebfdda39e367e72b71677173a71bc3ad0c881f Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 19 Nov 2019 10:09:25 -0800 Subject: [PATCH] Show full error logs at "--verbosity 0" so you can see command output without upping the verbosity level. --- NEWS | 4 ++++ borgmatic/commands/borgmatic.py | 15 ++++++++++----- setup.py | 2 +- tests/unit/commands/test_borgmatic.py | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 3d0f664..9714af5 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +1.4.13 + * Show full error logs at "--verbosity 0" so you can see command output without upping the + verbosity level. + 1.4.12 * #247: With "borgmatic check", consider Borg warnings as errors. * Dial back the display of inline error logs a bit, so failed command output doesn't appear diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 53d9049..17f95af 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -365,14 +365,16 @@ def load_configurations(config_filenames): return (configs, logs) -def log_record(**kwargs): +def log_record(suppress_log=False, **kwargs): ''' Create a log record based on the given makeLogRecord() arguments, one of which must be - named "levelno". Log the record and return it. + named "levelno". Log the record (unless suppress log is set) and return it. ''' record = logging.makeLogRecord(kwargs) - logger.handle(record) + if suppress_log: + return record + logger.handle(record) return record @@ -390,8 +392,11 @@ 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: - yield logging.makeLogRecord( - dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg=error.output) + yield log_record( + levelno=logging.CRITICAL, + levelname='CRITICAL', + msg=error.output, + suppress_log=bool(logger.getEffectiveLevel() < logging.WARNING), ) yield log_record(levelno=logging.CRITICAL, levelname='CRITICAL', msg=error) except (ValueError, OSError) as error: diff --git a/setup.py b/setup.py index c2cc588..081d5bf 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.4.12' +VERSION = '1.4.13' setup( diff --git a/tests/unit/commands/test_borgmatic.py b/tests/unit/commands/test_borgmatic.py index 8b3c835..c4e47ff 100644 --- a/tests/unit/commands/test_borgmatic.py +++ b/tests/unit/commands/test_borgmatic.py @@ -129,7 +129,7 @@ def test_make_error_log_records_generates_output_logs_for_message_only(): def test_make_error_log_records_generates_output_logs_for_called_process_error(): flexmock(module).should_receive('log_record').replace_with(dict) - flexmock(module.logging).should_receive('makeLogRecord').replace_with(dict) + flexmock(module.logger).should_receive('getEffectiveLevel').and_return(logging.WARNING) logs = tuple( module.make_error_log_records(