diff options
author | Tamaki Nishino <otamachan@gmail.com> | 2017-10-20 21:50:08 +0900 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-11-12 19:05:37 +0100 |
commit | 5dd8afda3ec83d245a4708638a40ca267d0dfed0 (patch) | |
tree | 01bee8ce3533eda3b30d3a49bed1e450491ae111 /systemd/test | |
parent | 397dec74114dcdc72728cbe3fe8fa6b982b44f1b (diff) | |
download | python-systemd-5dd8afda3ec83d245a4708638a40ca267d0dfed0.tar.gz |
journal: allow JournalHandler constructor to be called with args in a positional param
This change enables to add extra fields to JournalHandler in a
configuration file loaded by `logging.config.fileConfig`, which only allows positional
parameters:
class=systemd.journal.JournalHandler
args={'level': INFO, 'SYSLOG_IDENTIFIER': 'my-cool-app'}
[zj: originally the patch added a new positional parameter to
__init__(), but that is not backwards compatible. So I added a new
classmethod to allow the positional parameters to be passed.]
Diffstat (limited to 'systemd/test')
-rw-r--r-- | systemd/test/test_journal.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/systemd/test/test_journal.py b/systemd/test/test_journal.py index 49e4279..2f3cd3b 100644 --- a/systemd/test/test_journal.py +++ b/systemd/test/test_journal.py @@ -82,10 +82,14 @@ def test_journalhandler_init_exception(): kw = {' X ':3} with pytest.raises(ValueError): journal.JournalHandler(**kw) + with pytest.raises(ValueError): + journal.JournalHandler.with_args(kw) def test_journalhandler_init(): kw = {'X':3, 'X3':4} journal.JournalHandler(logging.INFO, **kw) + kw['level'] = logging.INFO + journal.JournalHandler.with_args(kw) def test_journalhandler_info(): record = logging.LogRecord('test-logger', logging.INFO, 'testpath', 1, 'test', None, None) @@ -98,6 +102,16 @@ def test_journalhandler_info(): assert 'X=3' in sender.buf[0] assert 'X3=4' in sender.buf[0] + sender = MockSender() + handler = journal.JournalHandler.with_args({'level':logging.INFO, 'X':3, 'X3':4, 'sender_function':sender.send}) + handler.emit(record) + assert len(sender.buf) == 1 + assert 'X=3' in sender.buf[0] + assert 'X3=4' in sender.buf[0] + + # just check that args==None doesn't cause an error + journal.JournalHandler.with_args() + def test_journalhandler_no_message_id(): record = logging.LogRecord('test-logger', logging.INFO, 'testpath', 1, 'test', None, None) sender = MockSender() |