From 8c8640d0abe6d98c837fb7840f9bffa99cee9dc6 Mon Sep 17 00:00:00 2001 From: palto42 <12280188+palto42@users.noreply.github.com> Date: Fri, 1 Nov 2019 18:42:24 +0100 Subject: [PATCH] file-logger replaces syslog --- borgmatic/logger.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/borgmatic/logger.py b/borgmatic/logger.py index 9d14c3d..9b4a795 100644 --- a/borgmatic/logger.py +++ b/borgmatic/logger.py @@ -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,)