file-logger replaces syslog
This commit is contained in:
parent
22640a9ca0
commit
8c8640d0ab
1 changed files with 13 additions and 11 deletions
|
@ -80,25 +80,27 @@ def configure_logging(console_log_level, syslog_log_level=None, log_file=None):
|
||||||
if syslog_log_level is None:
|
if syslog_log_level is None:
|
||||||
syslog_log_level = console_log_level
|
syslog_log_level = console_log_level
|
||||||
|
|
||||||
if log_file is None:
|
|
||||||
console_handler = logging.StreamHandler()
|
console_handler = logging.StreamHandler()
|
||||||
console_handler.setFormatter(Console_color_formatter())
|
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.setLevel(console_log_level)
|
console_handler.setLevel(console_log_level)
|
||||||
|
|
||||||
syslog_path = None
|
syslog_path = None
|
||||||
|
if log_file is None:
|
||||||
if os.path.exists('/dev/log'):
|
if os.path.exists('/dev/log'):
|
||||||
syslog_path = '/dev/log'
|
syslog_path = '/dev/log'
|
||||||
elif os.path.exists('/var/run/syslog'):
|
elif os.path.exists('/var/run/syslog'):
|
||||||
syslog_path = '/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 = 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:
|
||||||
|
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:
|
else:
|
||||||
handlers = (console_handler,)
|
handlers = (console_handler,)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue