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

This commit is contained in:
Dan Helfman 2019-11-25 10:31:09 -08:00
parent 55ebfdda39
commit f4a231420f
4 changed files with 23 additions and 15 deletions

4
NEWS
View file

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

View file

@ -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:')
[
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)
for log in parse_logs + summary_logs
if log.levelno >= logger.getEffectiveLevel()
]
if any(log.levelno == logging.CRITICAL for log in summary_logs):
if summary_logs_max_level >= logging.CRITICAL:
exit_with_help_link()

View file

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

View file

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