|
@@ -73,7 +73,7 @@ def color_text(color, message):
|
|
return '{}{}{}'.format(color, message, colorama.Style.RESET_ALL)
|
|
return '{}{}{}'.format(color, message, colorama.Style.RESET_ALL)
|
|
|
|
|
|
|
|
|
|
-def configure_logging(console_log_level, syslog_log_level=None):
|
|
|
|
|
|
+def configure_logging(console_log_level, syslog_log_level=None, log_file=None):
|
|
'''
|
|
'''
|
|
Configure logging to go to both the console and syslog. Use the given log levels, respectively.
|
|
Configure logging to go to both the console and syslog. Use the given log levels, respectively.
|
|
'''
|
|
'''
|
|
@@ -85,16 +85,29 @@ def configure_logging(console_log_level, syslog_log_level=None):
|
|
console_handler.setLevel(console_log_level)
|
|
console_handler.setLevel(console_log_level)
|
|
|
|
|
|
syslog_path = None
|
|
syslog_path = None
|
|
- if os.path.exists('/dev/log'):
|
|
|
|
- syslog_path = '/dev/log'
|
|
|
|
- elif os.path.exists('/var/run/syslog'):
|
|
|
|
- syslog_path = '/var/run/syslog'
|
|
|
|
|
|
+ if log_file is None:
|
|
|
|
+ if os.path.exists('/dev/log'):
|
|
|
|
+ syslog_path = '/dev/log'
|
|
|
|
+ elif os.path.exists('/var/run/syslog'):
|
|
|
|
+ syslog_path = '/var/run/syslog'
|
|
|
|
|
|
if syslog_path and not interactive_console():
|
|
if syslog_path and not interactive_console():
|
|
syslog_handler = logging.handlers.SysLogHandler(address=syslog_path)
|
|
syslog_handler = logging.handlers.SysLogHandler(address=syslog_path)
|
|
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)
|
|
syslog_handler.setLevel(syslog_log_level)
|
|
handlers = (console_handler, syslog_handler)
|
|
handlers = (console_handler, syslog_handler)
|
|
|
|
+ elif log_file:
|
|
|
|
+ try:
|
|
|
|
+ file_handler = logging.FileHandler(log_file)
|
|
|
|
+ except FileNotFoundError:
|
|
|
|
+ print("ERROR: Path to log-file doesn't exist: {}".format(log_file))
|
|
|
|
+ sys.exit(1)
|
|
|
|
+ except PermissionError:
|
|
|
|
+ print("ERROR: No write access to log-file: {}".format(log_file))
|
|
|
|
+ sys.exit(1)
|
|
|
|
+ file_handler.setFormatter(logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s'))
|
|
|
|
+ file_handler.setLevel(syslog_log_level)
|
|
|
|
+ handlers = (console_handler, file_handler)
|
|
else:
|
|
else:
|
|
handlers = (console_handler,)
|
|
handlers = (console_handler,)
|
|
|
|
|