idlesign / systemd-logging

Simplifies logging for systemd
https://github.com/idlesign/systemd-logging
BSD 3-Clause "New" or "Revised" License
26 stars 1 forks source link

Certain strings get interpreted by C when sent to the journal #3

Closed theblazehen closed 3 years ago

theblazehen commented 3 years ago

How to reproduce:

test.py:

import logging

from systemdlogging.toolbox import init_systemd_logging
init_systemd_logging()

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

logger.debug('0210122%2Fus-east-1%2Fs3%2Faws4')
print('0210122%2Fus-east-1%2Fs3%2Faws4')

systemd-run -t /path/to/venv/bin/python /path/to/test.py

The output to the journal then gives you 02101220.000000us-east-10.000000s30.000000aws4

What you expect: The output printed to the console, and the output printed to the journal should be the same

What happens: The output to the journal differs from the output to the console

theblazehen commented 3 years ago

It appears as if sd_journal_send

takes a series of format strings, each immediately followed by their associated parameters, terminated by NULL.

according to https://www.freedesktop.org/software/systemd/man/sd_journal_print.html.

Would sd_journal_print or sd_journal_sendv work?

idlesign commented 3 years ago

Thank you for the report. Worked it around in #4. You may want to give it a try before merge.

theblazehen commented 3 years ago

Thanks! Will give it a try

theblazehen commented 3 years ago

Just tested, thanks, it works!