diff --git a/NEWS b/NEWS index 1f58c70c..ac844a51 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,5 @@ 1.5.16.dev0 + * #407: Fix syslog logging on FreeBSD. * Better error messages! Switch the library used for validating configuration files (from pykwalify to jsonschema). * Link borgmatic Ansible role from installation documentation: diff --git a/borgmatic/logger.py b/borgmatic/logger.py index 84a31660..2d0bc1ca 100644 --- a/borgmatic/logger.py +++ b/borgmatic/logger.py @@ -152,6 +152,8 @@ def configure_logging( syslog_path = '/dev/log' elif os.path.exists('/var/run/syslog'): syslog_path = '/var/run/syslog' + elif os.path.exists('/var/run/log'): + syslog_path = '/var/run/log' if syslog_path and not interactive_console(): syslog_handler = logging.handlers.SysLogHandler(address=syslog_path) diff --git a/tests/unit/test_logger.py b/tests/unit/test_logger.py index 707376bc..ec46a588 100644 --- a/tests/unit/test_logger.py +++ b/tests/unit/test_logger.py @@ -179,6 +179,26 @@ def test_configure_logging_probes_for_log_socket_on_macos(): module.configure_logging(logging.INFO) +def test_configure_logging_probes_for_log_socket_on_freebsd(): + flexmock(module).should_receive('Multi_stream_handler').and_return( + flexmock(setFormatter=lambda formatter: None, setLevel=lambda level: None) + ) + flexmock(module).should_receive('Console_color_formatter') + flexmock(module).should_receive('interactive_console').and_return(False) + flexmock(module.logging).should_receive('basicConfig').with_args( + level=logging.INFO, handlers=tuple + ) + flexmock(module.os.path).should_receive('exists').with_args('/dev/log').and_return(False) + flexmock(module.os.path).should_receive('exists').with_args('/var/run/syslog').and_return(False) + flexmock(module.os.path).should_receive('exists').with_args('/var/run/log').and_return(True) + syslog_handler = logging.handlers.SysLogHandler() + flexmock(module.logging.handlers).should_receive('SysLogHandler').with_args( + address='/var/run/log' + ).and_return(syslog_handler).once() + + module.configure_logging(logging.INFO) + + def test_configure_logging_sets_global_logger_to_most_verbose_log_level(): flexmock(module).should_receive('Multi_stream_handler').and_return( flexmock(setFormatter=lambda formatter: None, setLevel=lambda level: None)