journald: Don't prefix message_id
field to make use of Journal Message Catalogs easier
#3111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Do not prefix event fields named
message_id
just like fields namedmessage
to enable easy use of Journal Message Catalogs.Motivation
Viewing the structured fields recorded in journald is very verbose and cumbersome.
One option is to use Journal Message Catalogs. journald catalogs provide templates that render log events with more information. They also support placeholders that get replaced by structured fields. This way it is way easier to access structured fields and inspect logs via
journalctl -x
.Log events and catalog entries are matched by the
MESSAGE_ID
. It is already possible to set themessage_id
field in tracing's log macros but only if no prefix is used. In contrast tomessage
,message_id
is not a special field and is therefore not exempt from prefixing. As a result, using Journal Message Catalogs, tracing-journald, and a prefix is currently not possible.Solution
This PR simply exempts fields named
message_id
from prefixing just like for fields calledmessage
.Future work
This PR is the first step to make using tracing-journald and Journal Message Catalogs together easier. I have a few ideas how this integration can be further improved, like creating catalog files from source code or generate specific log macros from catalog files, but this is way out of scope for this PR and maybe even this crate. However, this needs more discussions.
Target branch
This PR targets the
v0.1.x
branch as it holds the latest version oftrancing-journald
that is also published on crates.io. If this is not the correct target branch I'll gladly change it.