summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-03-19 15:03:36 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-03-19 15:07:59 -0400
commit2169cdea8d2850a8e4109b2d1f3980d44a361818 (patch)
tree0b540eb73d4c9774b231abf39246c4d0290c298a
parentaa5550a9b7bb6fc0297c2f1bcb404daed1496251 (diff)
downloadpython-systemd-2169cdea8d2850a8e4109b2d1f3980d44a361818.tar.gz
journal: do not convert extra args to string in JournalHandler
send() already does conversions in a type-specific way, and doing it in journal handler would defeat those conversions. In particular, UUIDs would be converted to early and have dashes.
-rw-r--r--systemd/journal.py10
-rw-r--r--systemd/test/test_journal.py2
2 files changed, 6 insertions, 6 deletions
diff --git a/systemd/journal.py b/systemd/journal.py
index c98a85b..cb37150 100644
--- a/systemd/journal.py
+++ b/systemd/journal.py
@@ -575,11 +575,10 @@ class JournalHandler(_logging.Handler):
try:
msg = self.format(record)
pri = self.map_priority(record.levelno)
- extras = {k: str(v) for k, v in self._extra.items()}
- extras.update({
- k: str(v) for k, v in record.__dict__.items()
- })
+ # defaults
+ extras = self._extra.copy()
+ # higher priority
if record.exc_text:
extras['EXCEPTION_TEXT'] = record.exc_text
@@ -589,6 +588,9 @@ class JournalHandler(_logging.Handler):
if record.args:
extras['CODE_ARGS'] = str(record.args)
+ # explicit arguments — highest priority
+ extras.update(record.__dict__)
+
self.send(msg,
PRIORITY=format(pri),
LOGGER=record.name,
diff --git a/systemd/test/test_journal.py b/systemd/test/test_journal.py
index 9b65069..49e4279 100644
--- a/systemd/test/test_journal.py
+++ b/systemd/test/test_journal.py
@@ -107,7 +107,6 @@ def test_journalhandler_no_message_id():
assert all(not m.startswith('MESSAGE_ID=') for m in sender.buf[0])
def test_journalhandler_message_id_on_handler():
- pytest.xfail()
record = logging.LogRecord('test-logger', logging.INFO, 'testpath', 1, 'test', None, None)
sender = MockSender()
handler = journal.JournalHandler(logging.INFO, sender_function=sender.send,
@@ -126,7 +125,6 @@ def test_journalhandler_message_id_on_handler_hex():
assert 'MESSAGE_ID=' + TEST_MID.hex in sender.buf[0]
def test_journalhandler_message_id_on_message():
- pytest.xfail()
record = logging.LogRecord('test-logger', logging.INFO, 'testpath', 1, 'test', None, None)
record.__dict__['MESSAGE_ID'] = TEST_MID2
sender = MockSender()