Show full error logs at "--verbosity 0" so you can see command output without upping the verbosity level.

This commit is contained in:
Dan Helfman 2019-11-19 10:09:25 -08:00
parent e63e2e0852
commit 55ebfdda39
4 changed files with 16 additions and 7 deletions

4
NEWS
View file

@ -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

View file

@ -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:

View file

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

View file

@ -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(