Skip to content

Commit 84371c2

Browse files
committed
journal: rename SENDER_FUNCTION to sender_function
Let's not try to make it look like a journal field. It should be a normal parameter. Followup for dce0a85.
1 parent 5498ad7 commit 84371c2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

systemd/journal.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,12 @@ class JournalHandler(_logging.Handler):
548548
`THREAD_NAME`, `CODE_FILE`, `CODE_LINE`, `CODE_FUNC`, `LOGGER` (name as
549549
supplied to getLogger call), `MESSAGE_ID` (optional, see above),
550550
`SYSLOG_IDENTIFIER` (defaults to sys.argv[0]).
551+
552+
The function used to actually send messages can be overridden using
553+
the `sender_function` parameter.
551554
"""
552555

553-
def __init__(self, level=_logging.NOTSET, **kwargs):
556+
def __init__(self, level=_logging.NOTSET, sender_function=send, **kwargs):
554557
super(JournalHandler, self).__init__(level)
555558

556559
for name in kwargs:
@@ -559,7 +562,7 @@ def __init__(self, level=_logging.NOTSET, **kwargs):
559562
if 'SYSLOG_IDENTIFIER' not in kwargs:
560563
kwargs['SYSLOG_IDENTIFIER'] = _sys.argv[0]
561564

562-
self.send = kwargs.pop('SENDER_FUNCTION', send)
565+
self.send = sender_function
563566
self._extra = kwargs
564567

565568
def emit(self, record):

systemd/test/test_journal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_journalhandler_info():
9090
record = logging.LogRecord('test-logger', logging.INFO, 'testpath', 1, 'test', None, None)
9191

9292
sender = MockSender()
93-
kw = {'X':3, 'X3':4, 'SENDER_FUNCTION': sender.send}
93+
kw = {'X':3, 'X3':4, 'sender_function': sender.send}
9494
handler = journal.JournalHandler(logging.INFO, **kw)
9595
handler.emit(record)
9696
assert len(sender.buf) == 1

0 commit comments

Comments
 (0)