Ver código fonte

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

Thomas Waldmann 9 anos atrás
pai
commit
25140e8c82
3 arquivos alterados com 20 adições e 8 exclusões
  1. 4 1
      borg/archiver.py
  2. 2 2
      borg/logger.py
  3. 14 5
      docs/usage.rst

+ 4 - 1
borg/archiver.py

@@ -646,6 +646,9 @@ class Archiver:
         common_parser = argparse.ArgumentParser(add_help=False, prog=prog)
         common_parser = argparse.ArgumentParser(add_help=False, prog=prog)
         common_parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', default=False,
         common_parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', default=False,
                                    help='verbose output')
                                    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,
         common_parser.add_argument('--show-rc', dest='show_rc', action='store_true', default=False,
                                    help='show/log the return code (rc)')
                                    help='show/log the return code (rc)')
         common_parser.add_argument('--no-files-cache', dest='cache_files', action='store_false',
         common_parser.add_argument('--no-files-cache', dest='cache_files', action='store_false',
@@ -1155,7 +1158,7 @@ class Archiver:
         self.verbose = args.verbose
         self.verbose = args.verbose
         RemoteRepository.remote_path = args.remote_path
         RemoteRepository.remote_path = args.remote_path
         RemoteRepository.umask = args.umask
         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()
         check_extension_modules()
         keys_dir = get_keys_dir()
         keys_dir = get_keys_dir()
         if not os.path.exists(keys_dir):
         if not os.path.exists(keys_dir):

+ 2 - 2
borg/logger.py

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

+ 14 - 5
docs/usage.rst

@@ -11,12 +11,21 @@ command in detail.
 General
 General
 -------
 -------
 
 
-Quiet by default
-~~~~~~~~~~~~~~~~
+Type of log output
+~~~~~~~~~~~~~~~~~~
+
+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
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 
-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.
+For some subcommands, using the ``-v`` or ``--verbose`` option will give you
+more informational output (at ``info`` level).
 
 
 Return codes
 Return codes
 ~~~~~~~~~~~~
 ~~~~~~~~~~~~