I installed systemd-python:
pip install systemd-python
My python code:
from systemd import journal
...
log = logging.getLogger('lookup')
log.addHandler(journal.JournaldLogHandler())
log.setLevel(logging.INFO)
I got this error:
Traceback (most recent call last):
File "/app/lookup.py", line 12, in <module>
log.addHandler(journal.JournaldLogHandler())
^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'systemd.journal' has no attribute 'JournaldLogHandler'. Did you mean: 'JournalHandler'?
You're using the wrong package. Instead of
systemd-python, you needcysystemd(which is the same as thesystemdpackage - but we should avoid this confusing alias)Install cysystemd:
1. Install the required linux packages:
apt install build-essential libsystemd-devapt install libsystemd-daemon-dev libsystemd-journal-devyum install gcc systemd-devel2. Install package with pip
pip install cysystemd3. Don't forget to change your import
from cysystemd import journal