Skip to content

Remove mid from journal.py #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 25, 2017
Merged

Remove mid from journal.py #46

merged 3 commits into from
Mar 25, 2017

Conversation

keszybz
Copy link
Member

@keszybz keszybz commented Mar 19, 2017

Replacement for #38, rebased and with some fixes on top and tests.

wesleybowman and others added 3 commits March 19, 2017 13:33
Removed mid variable from JournalHandler since the MESSAGE_ID is already
in the extras variable. MESSAGE_ID was being set to None, but this won't
appear in the logs.
MESSAGE_ID passing was broken before previous commit:
TypeError: send() got multiple values for keyword argument 'MESSAGE_ID'

With the previous commit it's broken differently:

______________________________ test_journalhandler_message_id_on_handler _______________________________

    def test_journalhandler_message_id_on_handler():
        record = logging.LogRecord('test-logger', logging.INFO, 'testpath', 1, 'test', None, None)
        sender = MockSender()
        handler = journal.JournalHandler(logging.INFO, sender_function=sender.send,
                                         MESSAGE_ID=TEST_MID)
        handler.emit(record)
        assert len(sender.buf) == 1
>       assert 'MESSAGE_ID=' + TEST_MID.hex in sender.buf[0]
E       assert ('MESSAGE_ID=' + '8441372f8dca4ca98694a6091fd8519f') in ['MESSAGE=test', 'MESSAGE_ID=8441372f-8dca-4ca9-8694-a6091fd8519f', 'CODE_FILE=testpath', 'CODE_LINE=1', 'name=test-logger', 'exc_info=None', ...]
E        +  where '8441372f8dca4ca98694a6091fd8519f' = UUID('8441372f-8dca-4ca9-8694-a6091fd8519f').hex

systemd/test/test_journal.py:116: AssertionError
______________________________ test_journalhandler_message_id_on_message _______________________________

    def test_journalhandler_message_id_on_message():
        record = logging.LogRecord('test-logger', logging.INFO, 'testpath', 1, 'test', None, None)
        record.__dict__['MESSAGE_ID'] = TEST_MID2
        sender = MockSender()
        handler = journal.JournalHandler(logging.INFO, sender_function=sender.send,
                                         MESSAGE_ID=TEST_MID)
        handler.emit(record)
        assert len(sender.buf) == 1
>       assert 'MESSAGE_ID=' + TEST_MID2.hex in sender.buf[0]
E       assert ('MESSAGE_ID=' + '8441370000000000000000001fd85000') in ['MESSAGE=test', 'MESSAGE_ID=84413700-0000-0000-0000-00001fd85000', 'CODE_FILE=testpath', 'CODE_LINE=1', 'name=test-logger', 'exc_info=None', ...]
E        +  where '8441370000000000000000001fd85000' = UUID('84413700-0000-0000-0000-00001fd85000').hex

systemd/test/test_journal.py:135: AssertionError
============================ 2 failed, 53 passed, 6 skipped in 0.16 seconds ============================
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.
@keszybz keszybz merged commit 2169cde into systemd:master Mar 25, 2017
@keszybz keszybz deleted the pr/38 branch March 26, 2017 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants