idlesign/systemd-logging

Certain strings get interpreted by C when sent to the journal

theblazehen opened this issue · 4 comments

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

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?

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

Thanks! Will give it a try

Just tested, thanks, it works!