file-logger replaces syslog

This commit is contained in:
palto42 2019-11-01 18:42:24 +01:00
parent 22640a9ca0
commit 8c8640d0ab

View file

@ -80,25 +80,27 @@ def configure_logging(console_log_level, syslog_log_level=None, log_file=None):
if syslog_log_level is None:
syslog_log_level = console_log_level
if log_file is None:
console_handler = logging.StreamHandler()
console_handler.setFormatter(Console_color_formatter())
else:
console_handler = logging.FileHandler(log_file)
console_handler.setFormatter(logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s'))
console_handler = logging.StreamHandler()
console_handler.setFormatter(Console_color_formatter())
console_handler.setLevel(console_log_level)
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() and log_file is None:
if syslog_path and not interactive_console():
syslog_handler = logging.handlers.SysLogHandler(address=syslog_path)
syslog_handler.setFormatter(logging.Formatter('borgmatic: %(levelname)s %(message)s'))
syslog_handler.setLevel(syslog_log_level)
handlers = (console_handler, syslog_handler)
elif log_file:
file_handler = logging.FileHandler(log_file)
file_handler.setFormatter(logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s'))
file_handler.setLevel(syslog_log_level)
handlers = (console_handler, file_handler)
else:
handlers = (console_handler,)