0

I have the following script that I run on both an Arch Linux machine as well as a Debian stretch machine. On the Arch Linux machine I'm able to find the random value that was logged, whereas I can't seem to retrieve it on the Debian machine.

Anyone know if I need to configure something in Debian differently? Or if this is just because I'm running an older version of systemd on Debian?

import logging
import random

from systemd.journal import JournalHandler

LOGGER = logging.getLogger("this_is_a_logger")
JOURNAL_HANDLER = JournalHandler()

JOURNAL_HANDLER.setFormatter(logging.Formatter("%(message)s"))

# add the journald handler to the current logger
LOGGER.addHandler(JOURNAL_HANDLER)

# optionally set the logging level
LOGGER.setLevel(logging.DEBUG)

LOGGER.info(
    "test log event to systemd!",
    extra={"RANDOM_NUMBER": random.randint(0, 10), "LEVEL": "INFO"},
)

The command I'm using to check if the random number was logged is:

journalctl  -S "10 minutes ago" \
            LOGGER="this_is_a_logger" \
            -o json-pretty \
            | jq -r  ".RANDOM_NUMBER"

1 Answer 1

1

No. You're using an outdated version of python-systemd; Debian stable has v233 while support for the logger adapter's extra= parameter was only added in version v234.

If you cannot upgrade the python module, use the 'raw' systemd.journal.send() API.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .