diff --git a/oslo_log/handlers.py b/oslo_log/handlers.py index 1ed4e0ca..4f4f054b 100644 --- a/oslo_log/handlers.py +++ b/oslo_log/handlers.py @@ -82,7 +82,7 @@ class OSJournalHandler(logging.Handler): 'request_id', ) - def __init__(self, facility): + def __init__(self, facility=None): if not journal: raise RuntimeError("Systemd bindings do not exist") diff --git a/oslo_log/tests/unit/test_log.py b/oslo_log/tests/unit/test_log.py index 40c0916c..239fb1f1 100644 --- a/oslo_log/tests/unit/test_log.py +++ b/oslo_log/tests/unit/test_log.py @@ -29,6 +29,10 @@ try: import syslog except ImportError: syslog = None +try: + from systemd import journal +except ImportError: + journal = None import tempfile import time from unittest import mock @@ -390,6 +394,15 @@ class OSJournalHandlerTestCase(BaseTestCase): self.addCleanup(self.journal.stop) log.setup(self.CONF, 'testing') + @testtools.skipUnless(journal, "systemd journal binding is not available") + def test_handler(self): + handler = handlers.OSJournalHandler() + handler.emit( + logging.LogRecord("foo", logging.INFO, + "path", 123, "hey!", + None, None)) + self.assertTrue(self.journal.send.called) + def test_emit(self): logger = log.getLogger('nova-test.foo') local_context = _fake_new_context()