new verbosity level "-1" for errors

This commit is contained in:
palto42 2019-11-03 09:55:19 +01:00
parent 93f453cecf
commit 18d3542fbc
4 changed files with 27 additions and 7 deletions

View file

@ -138,23 +138,23 @@ def parse_arguments(*unparsed_arguments):
'-v', '-v',
'--verbosity', '--verbosity',
type=int, type=int,
choices=range(0, 3), choices=range(-1, 3),
default=0, default=0,
help='Display verbose progress to the console (from none to lots: 0, 1, or 2)', help='Display verbose progress to the console (from none to lots: 0, 1, or 2) or only errors (-1)',
) )
global_group.add_argument( global_group.add_argument(
'--syslog-verbosity', '--syslog-verbosity',
type=int, type=int,
choices=range(0, 3), choices=range(-1, 3),
default=0, default=0,
help='Log verbose progress to syslog (from none to lots: 0, 1, or 2). Ignored when console is interactive or --log-file is given', help='Log verbose progress to syslog (from none to lots: 0, 1, or 2) or only errors (-1). Ignored when console is interactive or --log-file is given',
) )
global_group.add_argument( global_group.add_argument(
'--log-file-verbosity', '--log-file-verbosity',
type=int, type=int,
choices=range(0, 3), choices=range(-1, 3),
default=1, default=0,
help='Log verbose progress to log file (from none to lots: 0, 1, or 2). Only used when --log-file is given', help='Log verbose progress to log file (from none to lots: 0, 1, or 2) or only errors (-1). Only used when --log-file is given',
) )
global_group.add_argument( global_group.add_argument(
'--log-file', '--log-file',

View file

@ -1,5 +1,6 @@
import logging import logging
VERBOSITY_ERROR = -1
VERBOSITY_WARNING = 0 VERBOSITY_WARNING = 0
VERBOSITY_SOME = 1 VERBOSITY_SOME = 1
VERBOSITY_LOTS = 2 VERBOSITY_LOTS = 2
@ -10,6 +11,7 @@ def verbosity_to_log_level(verbosity):
Given a borgmatic verbosity value, return the corresponding Python log level. Given a borgmatic verbosity value, return the corresponding Python log level.
''' '''
return { return {
VERBOSITY_ERROR: logging.ERROR,
VERBOSITY_WARNING: logging.WARNING, VERBOSITY_WARNING: logging.WARNING,
VERBOSITY_SOME: logging.INFO, VERBOSITY_SOME: logging.INFO,
VERBOSITY_LOTS: logging.DEBUG, VERBOSITY_LOTS: logging.DEBUG,

View file

@ -15,6 +15,7 @@ def test_parse_arguments_with_no_arguments_uses_defaults():
assert global_arguments.excludes_filename is None assert global_arguments.excludes_filename is None
assert global_arguments.verbosity == 0 assert global_arguments.verbosity == 0
assert global_arguments.syslog_verbosity == 0 assert global_arguments.syslog_verbosity == 0
assert global_arguments.log_file_verbosity == 0
def test_parse_arguments_with_multiple_config_paths_parses_as_list(): def test_parse_arguments_with_multiple_config_paths_parses_as_list():
@ -26,6 +27,7 @@ def test_parse_arguments_with_multiple_config_paths_parses_as_list():
assert global_arguments.config_paths == ['myconfig', 'otherconfig'] assert global_arguments.config_paths == ['myconfig', 'otherconfig']
assert global_arguments.verbosity == 0 assert global_arguments.verbosity == 0
assert global_arguments.syslog_verbosity == 0 assert global_arguments.syslog_verbosity == 0
assert global_arguments.log_file_verbosity == 0
def test_parse_arguments_with_verbosity_overrides_default(): def test_parse_arguments_with_verbosity_overrides_default():
@ -39,6 +41,7 @@ def test_parse_arguments_with_verbosity_overrides_default():
assert global_arguments.excludes_filename is None assert global_arguments.excludes_filename is None
assert global_arguments.verbosity == 1 assert global_arguments.verbosity == 1
assert global_arguments.syslog_verbosity == 0 assert global_arguments.syslog_verbosity == 0
assert global_arguments.log_file_verbosity == 0
def test_parse_arguments_with_syslog_verbosity_overrides_default(): def test_parse_arguments_with_syslog_verbosity_overrides_default():
@ -54,6 +57,20 @@ def test_parse_arguments_with_syslog_verbosity_overrides_default():
assert global_arguments.syslog_verbosity == 2 assert global_arguments.syslog_verbosity == 2
def test_parse_arguments_with_log_file_verbosity_overrides_default():
config_paths = ['default']
flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
arguments = module.parse_arguments('--log-file-verbosity', '-1')
global_arguments = arguments['global']
assert global_arguments.config_paths == config_paths
assert global_arguments.excludes_filename is None
assert global_arguments.verbosity == 0
assert global_arguments.syslog_verbosity == 0
assert global_arguments.log_file_verbosity == -1
def test_parse_arguments_with_list_json_overrides_default(): def test_parse_arguments_with_list_json_overrides_default():
arguments = module.parse_arguments('list', '--json') arguments = module.parse_arguments('list', '--json')

View file

@ -17,6 +17,7 @@ def insert_logging_mock(log_level):
def test_verbosity_to_log_level_maps_known_verbosity_to_log_level(): def test_verbosity_to_log_level_maps_known_verbosity_to_log_level():
assert module.verbosity_to_log_level(module.VERBOSITY_SOME) == logging.INFO assert module.verbosity_to_log_level(module.VERBOSITY_SOME) == logging.INFO
assert module.verbosity_to_log_level(module.VERBOSITY_LOTS) == logging.DEBUG assert module.verbosity_to_log_level(module.VERBOSITY_LOTS) == logging.DEBUG
assert module.verbosity_to_log_level(module.VERBOSITY_ERROR) == logging.ERROR
def test_verbosity_to_log_level_maps_unknown_verbosity_to_warning_level(): def test_verbosity_to_log_level_maps_unknown_verbosity_to_warning_level():