-1

I am trying to move DNF logging from the default filehandler(/var/log/dnf.log) to JournalHandler as part of a task.

My basic code snippet for this under my .py

import sys
import logging

from systemd.journal import JournalHandler

log = logging.getLogger('demo')
log.propagate = False
log.addHandler(JournalHandler())
log.setLevel(logging.INFO)

But I am seeing the below error,

from systemd import journal
ImportError: No module named 'systemd'
  • I am using the Yocto cross compiler
  • I have the below configuration already
inherit systemd
SYSTEMD_AUTO_ENABLE = "enable"
DISTRO_FEATURES_append = " systemd python3-systemd"

My system already support systemd, the issue is with integrating systemd with DNF

ps -ef | grep systemd
root      2194     1  0 14:34 ?        00:00:01 /lib/systemd/systemd-journald
root      3567     1  0 14:34 ?        00:00:00 /lib/systemd/systemd-udevd
message+  3799     1  0 14:34 ?        00:00:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
root      3878     1  0 14:34 ?        00:00:00 /lib/systemd/systemd-logind
guest     7141     1  2 14:36 ?        00:00:00 /lib/systemd/systemd --user
guest     7174  7147  0 14:36 ttymxc3  00:00:00 grep --color=auto systemd

Is any solution for this plz...

I tried Yocto inherit. import sys and logging

zaheerk
  • 11
  • 2
  • From the tag: systemd questions should be for *programming questions* using systemd or its libraries. Questions about *configuring the daemon* (including writing unit files) are better directed to Unix & Linux: https://unix.stackexchange.com. Please delete this. – Rob Dec 08 '22 at 09:07

1 Answers1

0

Mhh maybe this works:

import sys
import logging

try:
    from systemd import journal
    log = logging.getLogger('demo')
    log.propagate = False
    log.addHandler(JournalHandler())
    log.setLevel(logging.INFO)
except ImportError:
    print("No module named 'systemd'")
TheKid
  • 1
  • I think your suggestion not addressing the 'import systemd' issue. 'from systemd' & 'from systemd.journal' has same effect here – zaheerk Dec 05 '22 at 15:23