X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fpython-systemd%2Fjournal.py;h=ab8661e987343f636f3fcd5351b72fe86120cd74;hb=518dc5dff557116db3f072eb9d0a9492b6226778;hp=533a8754a4f8ca6b09d7fb5fcc6322b222415af4;hpb=6a71de70e5f5a244b656d9ccb373cc7241033e15;p=elogind.git diff --git a/src/python-systemd/journal.py b/src/python-systemd/journal.py index 533a8754a..ab8661e98 100644 --- a/src/python-systemd/journal.py +++ b/src/python-systemd/journal.py @@ -26,6 +26,8 @@ import uuid import traceback as _traceback import os as _os import logging as _logging +if sys.version_info >= (3,): + from collections import ChainMap from syslog import (LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG) from ._journal import sendv, stream_fd @@ -90,7 +92,7 @@ class Journal(_Journal): def _convert_field(self, key, value): try: result = self.converters[key](value) - except KeyError: + except: # Default conversion in unicode try: result = _convert_unicode(value) @@ -101,20 +103,36 @@ class Journal(_Journal): def _convert_entry(self, entry): result = {} - for key, value in entry.iteritems(): + for key, value in entry.items(): if isinstance(value, list): result[key] = [self._convert_field(key, val) for val in value] else: result[key] = self._convert_field(key, value) return result - def get_next(self, *args, **kwargs): + def add_match(self, *args, **kwargs): + args = list(args) + args.extend(_make_line(key, val) for key, val in kwargs.items()) + for arg in args: + super(Journal, self).add_match(arg) + + def get_next(self, skip=1): return self._convert_entry( - super(Journal, self).get_next(*args, **kwargs)) + super(Journal, self).get_next(skip)) - def query_unique(self, key, *args, **kwargs): + def query_unique(self, key): return set(self._convert_field(key, value) - for value in super(Journal, self).query_unique(key, *args, **kwargs)) + for value in super(Journal, self).query_unique(key)) + + def seek_realtime(self, timestamp): + if isinstance(timestamp, datetime.datetime): + timestamp = float(timestamp.strftime("%s.%f")) + return super(Journal, self).seek_realtime(timestamp) + + def seek_monotonic(self, timestamp, bootid=None): + if isinstance(timestamp, datetime.timedelta): + timestamp = timestamp.totalseconds() + return super(Journal, self).seek_monotonic(timestamp, bootid) def log_level(self, level): """Sets maximum log level by setting matches for PRIORITY."""