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"