Là một dự án mã nguồn mở, systemd/python-systemd đã đạt 521 sao trên GitHub, ngôn ngữ C. Python wrappers for systemd functionality
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
There is one required argument — the message, and additional fields
can be specified as keyword arguments. Following the journald API, all
names are uppercase.
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.
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
Unlike the native C version of journald's sd_journal_send(),
printf-style substitution is not supported. Perform any substitution
using Python's f-strings first (or .format() or the % operator).
A ValueError is raised if sd_journald_sendv() results in an
error. This might happen if there are no arguments or one of them is
invalid.
A handler class for the Python logging framework is also provided:
This module may be compiled against any version of libsystemd. At
compilation time, any functionality that is not available in that
version is disabled, and the resulting binary module will depend on
symbols that were available at compilation time. This means that the
resulting binary module is compatible with that or any later version
of libsystemd. To obtain maximum possible functionality, this module
must be compile against suitably recent libsystemd.
Documentation
Online documentation can be found at freedesktop.org
To build it locally run:
ninja -C build html
Or use any other builder, see man sphinx-build for a list. The compiled docs will be e.g. in build/html.
Viewing Output
Quick way to view output with all fields as it comes in:
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/systemd/python-systemd là nguồn chính thức.
systemd/python-systemd có phải mã nguồn mở không?
Có — systemd/python-systemd phát hành theo license LGPL-2.1, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/systemd/python-systemd.
systemd/python-systemd là gì?
systemd/python-systemd (systemd/python-systemd) là dự án C trên GitHub. Theo mô tả gốc: Python wrappers for systemd functionality
Đọc đầy đủ README ở tab phía trên.
python-systemd có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về python-systemd.