-if sys.version_info >= (3,):
- _convert_unicode = functools.partial(str, encoding='utf-8')
-else:
- _convert_unicode = functools.partial(unicode, encoding='utf-8')
-
-class Journal(_Journal):
- def __init__(self, converters=None, *args, **kwargs):
- super(Journal, self).__init__(*args, **kwargs)
- if sys.version_info >= (3,3):
- self.converters = ChainMap()
+_IDENT_LETTER = set('ABCDEFGHIJKLMNOPQRTSUVWXYZ_')
+
+def _valid_field_name(s):
+ return not (set(s) - _IDENT_LETTER)
+
+class Reader(_Reader):
+ """Reader allows the access and filtering of systemd journal
+ entries. Note that in order to access the system journal, a
+ non-root user must be in the `systemd-journal` group.
+
+ Example usage to print out all informational or higher level
+ messages for systemd-udevd for this boot:
+
+ >>> j = journal.Reader()
+ >>> j.this_boot()
+ >>> j.log_level(journal.LOG_INFO)
+ >>> j.add_match(_SYSTEMD_UNIT="systemd-udevd.service")
+ >>> for entry in j:
+ ... print(entry['MESSAGE'])
+
+ See systemd.journal-fields(7) for more info on typical fields
+ found in the journal.
+ """
+ def __init__(self, flags=0, path=None, files=None, converters=None):
+ """Create an instance of Reader, which allows filtering and
+ return of journal entries.
+
+ Argument `flags` sets open flags of the journal, which can be one
+ of, or ORed combination of constants: LOCAL_ONLY (default) opens
+ journal on local machine only; RUNTIME_ONLY opens only
+ volatile journal files; and SYSTEM_ONLY opens only
+ journal files of system services and the kernel.
+
+ Argument `path` is the directory of journal files. Note that
+ `flags` and `path` are exclusive.
+
+ Argument `converters` is a dictionary which updates the
+ DEFAULT_CONVERTERS to convert journal field values. Field
+ names are used as keys into this dictionary. The values must
+ be single argument functions, which take a `bytes` object and
+ return a converted value. When there's no entry for a field
+ name, then the default UTF-8 decoding will be attempted. If
+ the conversion fails with a ValueError, unconverted bytes
+ object will be returned. (Note that ValueEror is a superclass
+ of UnicodeDecodeError).
+
+ Reader implements the context manager protocol: the journal
+ will be closed when exiting the block.
+ """
+ super(Reader, self).__init__(flags, path, files)
+ if _sys.version_info >= (3,3):
+ self.converters = _ChainMap()