Skip to content

python(): LogTemplate::format() now returns a bytes object#799

Merged
bazsi merged 2 commits intoaxoflow:mainfrom
MrAnno:python-template-unicode-errors
Sep 20, 2025
Merged

python(): LogTemplate::format() now returns a bytes object#799
bazsi merged 2 commits intoaxoflow:mainfrom
MrAnno:python-template-unicode-errors

Conversation

@MrAnno
Copy link
Contributor

@MrAnno MrAnno commented Sep 19, 2025

In the Python bindings, LogMessage is not UTF-8 or Unicode–safe by default.
This means developers must explicitly call decode() on message fields and handle any decoding errors themselves.

Since LogTemplate operates on LogMessage fields, this behavior also applies to it.

Breaking change:
When using templates, you now need to decode the result manually. For example:
format().decode("utf-8", errors="backslashreplace")

Conflicts with #797.

MrAnno added a commit to MrAnno/axosyslog that referenced this pull request Sep 19, 2025
Signed-off-by: László Várady <[email protected]>
@MrAnno MrAnno force-pushed the python-template-unicode-errors branch from 100f4e5 to fd51f01 Compare September 19, 2025 14:26
MrAnno added a commit to MrAnno/axosyslog that referenced this pull request Sep 19, 2025
Signed-off-by: László Várady <[email protected]>
@MrAnno MrAnno force-pushed the python-template-unicode-errors branch from fd51f01 to 70d32f6 Compare September 19, 2025 14:28
Unfortunately, LogMessage is not UTF-8 or Unicode-safe by default.
This property is inherited by the LogTemplate class as well because it
operates on LogMessage fields.

This is a breaking change. When using templates, you should call
`format().decode("utf-8", errors="backslashreplace")` or anything similar
to get a Python string.

Signed-off-by: László Várady <[email protected]>
Signed-off-by: László Várady <[email protected]>
@MrAnno MrAnno force-pushed the python-template-unicode-errors branch from 70d32f6 to 5a27225 Compare September 19, 2025 14:35
Copy link
Member

@bazsi bazsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LogTemplate().format() returning bytes makes a lot of sense. This is the only use of LogTemplate that is shipped with AxoSyslog itself. I did not test the code, but the change looks good to me.

@bazsi bazsi merged commit ae7e992 into axoflow:main Sep 20, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants