Guidelines regarding structured logging usage
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.5k
- Forks
- 289
- Avg merge
- 55m
- Merged PRs (30d)
- 1
Description
What data should be put into structured logging attributes? Everything? Or only unimportant meta-information? If everything, should text message duplicate data already included in KV attributes?
// 1. only minor meta-information
log::error!(target: "pusher", "Push for client {uuid} failed: {err}");
// 2. everything, text message duplicates data
log::error!(target: "pusher", uuid:?, err:%; "Push for client {uuid} failed: {err}");
// 3. everything, text message doesn't include data logged into kv attributes
log::error!(target: "pusher", uuid:?, err:%; "Push for client failed");
- This option seems inferior to me, as you can't effectively filter log entries by error or client.
- Some loggers, notably,
env_loggerin its default configuration, will print both message and KVs to the console, which is redundant and ugly. However, it works fine forsystemd-journal-logger:journalctlprints only the text message by default (+ timestamp). And you can also filter by KV attributes, as they're stored as custom journal fields. - Some loggers, notably,
systemd-journal-logger, will store only the text message intoMESSAGEjournal field, and store the KVs as custom journal fields.journalctlwill only show the text, and important error details can only be retrieved withjournalctl -o verbose, and its output is too noisy to use for typical log-reading activities. In contrast, this record is rendered perfectly byenv_logger:message key1=value1 key2=value2 ...
I think log is missing concrete guidelines regarding stuctured logging usage. Although output format is configurable in many loggers, it isn't in systemd-journal-logger, and you're still out of luck if combine different libraries that log using different conventions.
/cc @swsnr
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is identified. Start by reviewing the issue's three structured-logging examples and the linked logger behavior, then determine whether the project can reach a concrete convention. Done means an agreed guideline covering structured attributes, message duplication, and differing logger output is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- observability-sre
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100