chiark / gitweb /
systemd-python: downgrade _reader.c to C89
[elogind.git] / src / python-systemd / journal.py
index d61c30e1244c825ac3054443fbeb82cf52713963..d63722b91dc0329472d7e0a7a6e8e43190657eb5 100644 (file)
@@ -79,6 +79,24 @@ else:
     _convert_unicode = _functools.partial(unicode, encoding='utf-8')
 
 class Journal(_Journal):
+    """Journal 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 `adm` group.
+
+    Example usage to print out all error or higher level messages
+    for systemd-udevd for the boot:
+
+    >>> myjournal = journal.Journal()
+    >>> myjournal.add_boot_match(journal.CURRENT_BOOT)
+    >>> myjournal.add_loglevel_matches(journal.LOG_ERR)
+    >>> myjournal.add_match(_SYSTEMD_UNIT="systemd-udevd.service")
+    >>> from __future__ import print_function
+    >>> for entry in myjournal:
+    ...    print(entry['MESSAGE'])
+
+    See man page "systemd.journal-fields" for more info on
+    typical fields found in the journal.
+    """
     def __init__(self, converters=None, flags=LOCAL_ONLY, path=None):
         """Creates instance of Journal, which allows filtering and
         return of journal entries.
@@ -113,7 +131,7 @@ class Journal(_Journal):
             # Default conversion in unicode
             try:
                 result = _convert_unicode(value)
-            except:
+            except UnicodeDecodeError:
                 # Leave in default bytes
                 result = value
         return result