Skip to content

Commit

Permalink
Show full error logs at "--verbosity 0" so you can see command output…
Browse files Browse the repository at this point in the history
… without upping the verbosity level.
  • Loading branch information
witten committed Nov 19, 2019
1 parent e63e2e0 commit 55ebfdd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 10 additions & 5 deletions borgmatic/commands/borgmatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import find_packages, setup

VERSION = '1.4.12'
VERSION = '1.4.13'


setup(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/commands/test_borgmatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 55ebfdd

Please sign in to comment.