[systemd-devel] Python journal reader
David Strauss
david at davidstrauss.net
Sat Apr 13 15:00:53 PDT 2013
If seems like we should put the conditional special handling for
__REALTIME_TIMESTAMP and __MONOTONIC_TIMESTAMP in either _reader.c or
right in get().
Here's why:
* With the code above, calling Reader.get('__REALTIME_TIMESTAMP')
results in the wrong type (if anything, I'd need to check), but
Reader.get_realtime() gives the right thing.
* The type of Reader.get('__REALTIME_TIMESTAMP') is different from
Reader.get_next()['__REALTIME_TIMESTAMP'], and it should be
equivalent.
On Fri, Apr 12, 2013 at 10:13 AM, Steven Hiscocks
<steven-systemd at hiscocks.me.uk> wrote:
> Hi,
>
> In the python journal Reader, the splitting out of monotonic and realtime
> stamps, has affected `get_next` function as timestamp values are no longer
> present in the dictionary returned. Also the new `get_monotonic` and
> `get_realtime` functions are not run through the converters. Equally, the
> 'get' method added is not run through the converters. I also noted the
> additional `next` method doesn't work on python2, as it clashes with the
> iter `next` method (python3 not affected as it changes iter method to
> `__next__`)
>
> My suggestion with the python Reader `get_next` method is that the realtime
> and monotonic timestamps remain part of it, as these are key parts of a log
> entry, and two more lines in everyone's code to get them seems cumbersome.
> Equally also the cursor value. This also makes the output fields the same as
> the journalctl json format. (I agree it makes sense the _Reader object
> element to remain separate so close to actual C API).
>
> I'm not sure what the best approach to the `next` method issue is…
>
> Proposed changes below. I've add `get_cursor` to go through converters for
> consistency, even if not required currently.
>
> ```
> diff --git a/src/python-systemd/journal.py b/src/python-systemd/journal.py
> index 48f57ac..c163ff7 100644
> --- a/src/python-systemd/journal.py
> +++ b/src/python-systemd/journal.py
> @@ -189,6 +189,21 @@ class Reader(_Reader):
> for arg in args:
> super(Reader, self).add_match(arg)
>
> + def get(self, key):
> + return self._convert_field(key, super(Reader, self).get(key))
> +
> + def get_realtime(self):
> + return self._convert_field(
> + '__REALTIME_TIMESTAMP', super(Reader, self).get_realtime())
> +
> + def get_monotonic(self):
> + return self._convert_field(
> + '__MONOTONIC_TIMESTAMP', super(Reader, self).get_monotonic())
> +
> + def get_cursor(self):
> + return self._convert_field(
> + '__CURSOR', super(Reader, self).get_cursor())
> +
> def get_next(self, skip=1):
> """Return the next log entry as a dictionary of fields.
>
> @@ -197,8 +212,13 @@ class Reader(_Reader):
> Entries will be processed with converters specified during
> Reader creation.
> """
> - return self._convert_entry(
> + entry = self._convert_entry(
> super(Reader, self).get_next(skip))
> + entry['__REALTIME_TIMESTAMP'] = self.get_realtime()
> + entry['__MONOTONIC_TIMESTAMP'] = self.get_monotonic()
> + entry['__CURSOR'] = self.get_cursor()
> +
> + return entry
>
> def query_unique(self, field):
> """Return unique values appearing in the journal for given `field`.
> ```
>
> Thanks
> --
> Steven Hiscocks
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
David Strauss
| david at davidstrauss.net
| +1 512 577 5827 [mobile]
More information about the systemd-devel
mailing list