فهرست منبع

Add separate syslog verbosity flag.

Dan Helfman 6 سال پیش
والد
کامیت
9ceeae2de0
2فایلهای تغییر یافته به همراه27 افزوده شده و 8 حذف شده
  1. 14 3
      borgmatic/commands/borgmatic.py
  2. 13 5
      borgmatic/logger.py

+ 14 - 3
borgmatic/commands/borgmatic.py

@@ -176,7 +176,14 @@ def parse_arguments(*arguments):
         type=int,
         type=int,
         choices=range(0, 3),
         choices=range(0, 3),
         default=0,
         default=0,
-        help='Display verbose progress (1 for some, 2 for lots)',
+        help='Display verbose progress to the console (from none to lots: 0, 1, or 2)',
+    )
+    common_group.add_argument(
+        '--syslog-verbosity',
+        type=int,
+        choices=range(0, 3),
+        default=2,
+        help='Display verbose progress to syslog (from none to lots: 0, 1, or 2)',
     )
     )
     common_group.add_argument(
     common_group.add_argument(
         '--version',
         '--version',
@@ -483,14 +490,18 @@ def main():  # pragma: no cover
         configure_logging(logging.CRITICAL)
         configure_logging(logging.CRITICAL)
         logger.critical(error)
         logger.critical(error)
         exit_with_help_link()
         exit_with_help_link()
-    except SystemExit:
+    except SystemExit as error:
+        if error.code == 0:
+            raise error
         configure_logging(logging.CRITICAL)
         configure_logging(logging.CRITICAL)
         logger.critical('Error parsing arguments: {}'.format(' '.join(sys.argv)))
         logger.critical('Error parsing arguments: {}'.format(' '.join(sys.argv)))
         exit_with_help_link()
         exit_with_help_link()
 
 
     colorama.init(autoreset=True, strip=not should_do_markup(args.no_color))
     colorama.init(autoreset=True, strip=not should_do_markup(args.no_color))
 
 
-    configure_logging(verbosity_to_log_level(args.verbosity))
+    configure_logging(
+        verbosity_to_log_level(args.verbosity), verbosity_to_log_level(args.syslog_verbosity)
+    )
 
 
     if args.version:
     if args.version:
         print(pkg_resources.require('borgmatic')[0].version)
         print(pkg_resources.require('borgmatic')[0].version)

+ 13 - 5
borgmatic/logger.py

@@ -103,14 +103,22 @@ def color_text(color, message):
     return '{}{}{}'.format(color, message, colorama.Style.RESET_ALL)
     return '{}{}{}'.format(color, message, colorama.Style.RESET_ALL)
 
 
 
 
-def configure_logging(log_level):
+def configure_logging(console_log_level, syslog_log_level=None):
     '''
     '''
-    Configure logging to go to both the console and syslog. Use the given log level for both.
+    Configure logging to go to both the console and syslog. Use the given log levels, respectively.
     '''
     '''
+    if syslog_log_level is None:
+        syslog_log_level = console_log_level
+
+    console_handler = logging.StreamHandler()
+    console_handler.setFormatter(logging.Formatter('%(message)s'))
+    console_handler.setLevel(console_log_level)
+
     syslog_handler = logging.handlers.SysLogHandler(address='/dev/log')
     syslog_handler = logging.handlers.SysLogHandler(address='/dev/log')
     syslog_handler.setFormatter(logging.Formatter('borgmatic: %(levelname)s %(message)s'))
     syslog_handler.setFormatter(logging.Formatter('borgmatic: %(levelname)s %(message)s'))
+    syslog_handler.setLevel(syslog_log_level)
+
     logging.basicConfig(
     logging.basicConfig(
-        level=log_level,
-        format='%(message)s',
-        handlers=(logging.StreamHandler(), syslog_handler),
+        level=min(console_log_level, syslog_log_level),
+        handlers=(console_handler, syslog_handler),
     )
     )