Add test for #407: Fix syslog logging on FreeBSD.

This commit is contained in:
Dan Helfman 2021-06-23 10:21:45 -07:00
parent 27d37b606b
commit 54d57e1349
3 changed files with 23 additions and 0 deletions

1
NEWS
View File

@ -1,4 +1,5 @@
1.5.16.dev0 1.5.16.dev0
* #407: Fix syslog logging on FreeBSD.
* Better error messages! Switch the library used for validating configuration files (from pykwalify * Better error messages! Switch the library used for validating configuration files (from pykwalify
to jsonschema). to jsonschema).
* Link borgmatic Ansible role from installation documentation: * Link borgmatic Ansible role from installation documentation:

View File

@ -152,6 +152,8 @@ def configure_logging(
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'
elif os.path.exists('/var/run/log'):
syslog_path = '/var/run/log'
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)

View File

@ -179,6 +179,26 @@ def test_configure_logging_probes_for_log_socket_on_macos():
module.configure_logging(logging.INFO) 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(): def test_configure_logging_sets_global_logger_to_most_verbose_log_level():
flexmock(module).should_receive('Multi_stream_handler').and_return( flexmock(module).should_receive('Multi_stream_handler').and_return(
flexmock(setFormatter=lambda formatter: None, setLevel=lambda level: None) flexmock(setFormatter=lambda formatter: None, setLevel=lambda level: None)