From 25140e8c8218fe19ef9ffc8029e3f53516b2d546 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 21 Nov 2015 02:09:16 +0100 Subject: [PATCH] add --log-level to set the level of the builtin logging configuration, fixes #426 --- borg/archiver.py | 5 ++++- borg/logger.py | 4 ++-- docs/usage.rst | 19 ++++++++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/borg/archiver.py b/borg/archiver.py index 73fc5098e..7a2b5db42 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -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): diff --git a/borg/logger.py b/borg/logger.py index 07bb37709..a40f676c7 100644 --- a/borg/logger.py +++ b/borg/logger.py @@ -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: diff --git a/docs/usage.rst b/docs/usage.rst index d7515f679..5bba83904 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -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 ~~~~~~~~~~~~