[systemd-devel] python - reading the journal

Steven Hiscocks steven-systemd at hiscocks.me.uk
Mon Feb 4 10:30:45 PST 2013

On 04/02/13 05:13, David Strauss wrote:
> I second the interest in committing this to the existing Python
> support once polished.
> On Sun, Feb 3, 2013 at 6:07 PM, Zbigniew Jędrzejewski-Szmek
> <zbyszek at in.waw.pl> wrote:
>> On Sun, Feb 03, 2013 at 09:18:28PM +0000, Steven Hiscocks wrote:
>>> Hi,
>>> I've been developing a python module for accessing the journal,
>>> using the journal API. (https://github.com/kwirk/pyjournalctl)
>> Great! Have you thought about including it in the systemd repo,
>> once interface nad implementation is stabilized?
>>> One issue I've had is with 'sd_journal_seek_monotonic_usec'. When
>>> called, followed by call to 'sd_journal_next', I end up at the start
>>> of the journal.
>>> If I set a match for "_BOOT_ID" , before (or after) the call to
>>> 'sd_journal_seek_monotonic_usec' (with same "_BOOT_ID"), it then
>>> behaves as I would expect and returns the closest log entry to the
>>> monotonic time stamp.
>>> I was wondering if this is this the intended behaviour, or is this a bug?
>> Looking at the docs, it seems OK. Without _BOOT_ID the behaviour
>> is unspecified.
>> Some comments about the API:
>>>>> journal.add_match("PRIORITY", "5")
>> Why not journal.add_match(PRIORITY="5") ?
>> Likewise journal.add_matches({"PRIORITY": "5", "_PID": "1"})
>> could be written as journal.add_matches(PRIORITY=5, _PID=1).
>> This would mirror the journal API which is part of the python-systemd
>> module.
>> Note: systemd.journal already has LOG_EMERG and friends (imported
>> from syslog), so there's no need to use plain numbers.
>> Your object-oriented approach, python 2/3 compatiblity, GIL releasing
>> support are great. I would definitely want to pull this into the
>> python-systemd.
>> Zbyszek

Thanks both for the positive feedback.

So if I understand correctly, a _BOOT_ID match must be in place for 
sd_journal_seek_monotonic_usec to function correctly?

It would be great for it too be included in the systemd repo! I'll look 
at making the suggested changes. I think that using keyword arguments 
will make add_matches redundant, so I'll probably drop that and just 
have the add_match method.

Steven Hiscocks

More information about the systemd-devel mailing list