summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS22
-rw-r--r--README.md74
2 files changed, 90 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index 9cf35f4..17e3b82 100644
--- a/NEWS
+++ b/NEWS
@@ -2,11 +2,25 @@ Python wrappers for libsystemd API
CHANGES WITH 235:
- * Adapt the rename of systemd-activate to systemd-socket-activate
- performed in systemd 230
+ * Adapt the rename of systemd-activate to systemd-socket-activate
+ performed in systemd 230.
- * Support for the new sd_listen_fds_with_names added in systemd 227
- is added.
+ * Support for the new sd_listen_fds_with_names added in systemd 227
+ is added.
+
+ * Make the Reader PY_SSIZE_T_CLEAN for py3.10 compatibility.
+
+ * id128: update for systemd-243 compatibility and other fixes.
+
+ * C syntax modernization. A minimum of C99 is assumed.
+
+ * Fix seek_realtime to work with timezone aware date.
+
+ * journal: add namespace support.
+
+ * Memory leak fixes.
+
+ * Documentation and other fixes.
CHANGES WITH 234:
diff --git a/README.md b/README.md
index 2beb373..514c5d0 100644
--- a/README.md
+++ b/README.md
@@ -76,6 +76,76 @@ The journald sendv call can also be accessed directly:
The two examples should give the same results in the log.
+Reading from the journal is often similar to using the `journalctl` utility.
+
+Show all entries since 20 minutes ago (`journalctl --since "20 minutes ago"`):
+
+ from systemd import journal
+ from datetime import datetime, timedelta
+ j = journal.Reader()
+ j.seek_realtime(datetime.now() - timedelta(minutes=20))
+ for entry in j:
+ print(entry['MESSAGE'])
+
+Show entries between two timestamps (`journalctl --since "50 minutes ago" --until "10 minutes ago"`):
+
+ from systemd import journal
+ from datetime import datetime, timedelta
+ j = journal.Reader()
+ since = datetime.now() - timedelta(minutes=50)
+ until = datetime.now() - timedelta(minutes=10)
+ j.seek_realtime(since)
+ for entry in j:
+ if entry['__REALTIME_TIMESTAMP'] > until:
+ break
+ print(entry['MESSAGE'])
+
+Show explanations of log messages alongside entries (`journalctl -x`):
+
+ from systemd import journal
+ j = journal.Reader()
+ for entry in j:
+ print("MESSAGE: ", entry['MESSAGE'])
+ try:
+ print("CATALOG: ", j.get_catalog())
+ except:
+ pass
+
+Show entries by a specific executable (`journalctl /usr/bin/vim`):
+
+ from systemd import journal
+ j = journal.Reader()
+ j.add_match('_EXE=/usr/bin/vim')
+ for entry in j:
+ print(entry['MESSAGE'])
+
+ - Note: matches can be added from many different fields, for example entries from a specific process ID can be matched with the `_PID` field, and entries from a specific unit (ie. `journalctl -u systemd-udevd.service`) can be matched with `_SYSTEMD_UNIT`. See all fields available at the [systemd.journal-fields docs](https://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html).
+
+Show kernel ring buffer (`journalctl -k`):
+
+ from systemd import journal
+ j = journal.Reader()
+ j.add_match('_TRANSPORT=kernel')
+ for entry in j:
+ print(entry['MESSAGE'])
+
+Read entries in reverse (`journalctl _EXE=/usr/bin/vim -r`):
+
+ from systemd import journal
+ class ReverseReader(journal.Reader):
+ def __next__(self):
+ ans = self.get_previous()
+ if ans:
+ return ans
+ raise StopIteration()
+
+ j = ReverseReader()
+ j.add_match('_EXE=/usr/bin/vim')
+ j.seek_tail()
+ for entry in j:
+ print(entry['MESSAGE'])
+
+
Notes
-----
@@ -92,10 +162,10 @@ A handler class for the Python logging framework is also provided:
import logging
from systemd import journal
logger = logging.getLogger('custom_logger_name')
- logger.addHandler(journal.JournalHandler())
+ logger.addHandler(journal.JournalHandler(SYSLOG_IDENTIFIER='custom_unit_name'))
logger.warning("Some message: %s", 'detail')
-libsytemd version compatibility
+libsystemd version compatibility
-------------------------------
This module may be compiled against any version of libsystemd. At