tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.53k stars 725 forks source link

journald: Don't prefix `message_id` field to make use of Journal Message Catalogs easier #3111

Open MattesWhite opened 1 month ago

MattesWhite commented 1 month ago

Do not prefix event fields named message_id just like fields named message 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 the message_id field in tracing's log macros but only if no prefix is used. In contrast to message, 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 called message.

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 of trancing-journald that is also published on crates.io. If this is not the correct target branch I'll gladly change it.