chiark / gitweb /
systemd-python: implement this_boot/this_machine in Python
[elogind.git] / src / python-systemd / journal.py
index 8a688f978b569ad102eb62597b1f1ad814590e8f..533a8754a4f8ca6b09d7fb5fcc6322b222415af4 100644 (file)
@@ -31,6 +31,7 @@ from syslog import (LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
 from ._journal import sendv, stream_fd
 from ._reader import (_Journal, NOP, APPEND, INVALIDATE,
                       LOCAL_ONLY, RUNTIME_ONLY, SYSTEM_ONLY)
+from . import id128 as _id128
 
 _MONOTONIC_CONVERTER = lambda x: datetime.timedelta(microseconds=float(x))
 _REALTIME_CONVERTER = lambda x: datetime.datetime.fromtimestamp(float(x)/1E6)
@@ -115,6 +116,22 @@ class Journal(_Journal):
         return set(self._convert_field(key, value)
             for value in super(Journal, self).query_unique(key, *args, **kwargs))
 
+    def log_level(self, level):
+        """Sets maximum log level by setting matches for PRIORITY."""
+        if 0 <= level <= 7:
+            for i in range(level+1):
+                self.add_match(PRIORITY="%s" % i)
+        else:
+            raise ValueError("Log level must be 0 <= level <= 7")
+
+    def this_boot(self):
+        """Add match for _BOOT_ID equal to current boot ID."""
+        self.add_match(_BOOT_ID=_id128.get_boot().hex)
+
+    def this_machine(self):
+        """Add match for _MACHINE_ID equal to the ID of this machine."""
+        self.add_match(_MACHINE_ID=_id128.get_machine().hex)
+
 def _make_line(field, value):
         if isinstance(value, bytes):
                 return field.encode('utf-8') + b'=' + value