add --log-level to set the level of the builtin logging configuration, fixes #426

This commit is contained in:
Thomas Waldmann 2015-11-21 02:09:16 +01:00
parent e372dfb834
commit 25140e8c82
3 changed files with 20 additions and 8 deletions

View File

@ -646,6 +646,9 @@ class Archiver:
common_parser = argparse.ArgumentParser(add_help=False, prog=prog)
common_parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', default=False,
help='verbose output')
common_parser.add_argument('--log-level', dest='log_level', default='info', metavar='LEVEL',
choices=('debug', 'info', 'warning', 'error', 'critical'),
help='set the log level to LEVEL, default: %(default)s)')
common_parser.add_argument('--show-rc', dest='show_rc', action='store_true', default=False,
help='show/log the return code (rc)')
common_parser.add_argument('--no-files-cache', dest='cache_files', action='store_false',
@ -1155,7 +1158,7 @@ class Archiver:
self.verbose = args.verbose
RemoteRepository.remote_path = args.remote_path
RemoteRepository.umask = args.umask
setup_logging() # do not use loggers before this!
setup_logging(level=args.log_level) # do not use loggers before this!
check_extension_modules()
keys_dir = get_keys_dir()
if not os.path.exists(keys_dir):

View File

@ -52,7 +52,7 @@ def _log_warning(message, category, filename, lineno, file=None, line=None):
logger.warning(msg)
def setup_logging(stream=None, conf_fname=None, env_var='BORG_LOGGING_CONF'):
def setup_logging(stream=None, conf_fname=None, env_var='BORG_LOGGING_CONF', level='info'):
"""setup logging module according to the arguments provided
if conf_fname is given (or the config file name can be determined via
@ -88,7 +88,7 @@ def setup_logging(stream=None, conf_fname=None, env_var='BORG_LOGGING_CONF'):
# example:
# handler.setFormatter(logging.Formatter('%(name)s: %(message)s'))
logger.addHandler(handler)
logger.setLevel(logging.INFO)
logger.setLevel(level.upper())
configured = True
logger = logging.getLogger(__name__)
if err_msg:

View File

@ -11,12 +11,21 @@ command in detail.
General
-------
Quiet by default
~~~~~~~~~~~~~~~~
Type of log output
~~~~~~~~~~~~~~~~~~
Like most UNIX commands |project_name| is quiet by default but the ``-v`` or
``--verbose`` option can be used to get the program to output more status
messages as it is processing.
You can set the log level of the builtin logging configuration using the
--log-level option.
Supported levels: ``debug``, ``info``, ``warning``, ``error``, ``critical``.
All log messages created with at least the given level will be output.
Amount of informational output
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For some subcommands, using the ``-v`` or ``--verbose`` option will give you
more informational output (at ``info`` level).
Return codes
~~~~~~~~~~~~