diff options
-rw-r--r-- | systemd/journal.py | 7 | ||||
-rw-r--r-- | systemd/test/test_journal.py | 2 |
2 files changed, 6 insertions, 3 deletions
diff --git a/systemd/journal.py b/systemd/journal.py index 39e87ec..e23e5a5 100644 --- a/systemd/journal.py +++ b/systemd/journal.py @@ -548,9 +548,12 @@ class JournalHandler(_logging.Handler): `THREAD_NAME`, `CODE_FILE`, `CODE_LINE`, `CODE_FUNC`, `LOGGER` (name as supplied to getLogger call), `MESSAGE_ID` (optional, see above), `SYSLOG_IDENTIFIER` (defaults to sys.argv[0]). + + The function used to actually send messages can be overridden using + the `sender_function` parameter. """ - def __init__(self, level=_logging.NOTSET, **kwargs): + def __init__(self, level=_logging.NOTSET, sender_function=send, **kwargs): super(JournalHandler, self).__init__(level) for name in kwargs: @@ -559,7 +562,7 @@ class JournalHandler(_logging.Handler): if 'SYSLOG_IDENTIFIER' not in kwargs: kwargs['SYSLOG_IDENTIFIER'] = _sys.argv[0] - self.send = kwargs.pop('SENDER_FUNCTION', send) + self.send = sender_function self._extra = kwargs def emit(self, record): diff --git a/systemd/test/test_journal.py b/systemd/test/test_journal.py index ce6ba97..93b966e 100644 --- a/systemd/test/test_journal.py +++ b/systemd/test/test_journal.py @@ -90,7 +90,7 @@ def test_journalhandler_info(): record = logging.LogRecord('test-logger', logging.INFO, 'testpath', 1, 'test', None, None) sender = MockSender() - kw = {'X':3, 'X3':4, 'SENDER_FUNCTION': sender.send} + kw = {'X':3, 'X3':4, 'sender_function': sender.send} handler = journal.JournalHandler(logging.INFO, **kw) handler.emit(record) assert len(sender.buf) == 1 |