systemd-python AttributeError: module 'systemd.journal' has no attribute 'JournaldLogHandler'

44 views Asked by At

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'?
1

There are 1 answers

0
DaWe On

You're using the wrong package. Instead of systemd-python, you need cysystemd (which is the same as the systemd package - but we should avoid this confusing alias)

Install cysystemd:

1. Install the required linux packages:
  • For Debian/Ubuntu users:

apt install build-essential libsystemd-dev

  • On older versions of Debian/Ubuntu, you might also need to install:

apt install libsystemd-daemon-dev libsystemd-journal-dev

  • For CentOS/RHEL

yum install gcc systemd-devel

2. Install package with pip

pip install cysystemd

3. Don't forget to change your import

from cysystemd import journal