Skip to content

feat(fmt): support systemd journal priority prefixes#408

Closed
sant0s12 wants to merge 1 commit into
rust-cli:mainfrom
sant0s12:feat/journal-prefix
Closed

feat(fmt): support systemd journal priority prefixes#408
sant0s12 wants to merge 1 commit into
rust-cli:mainfrom
sant0s12:feat/journal-prefix

Conversation

@sant0s12
Copy link
Copy Markdown

When JOURNAL_STREAM is set, log lines are prefixed with <N> (syslog priority) so journald picks up the correct severity.

API

use env_logger::{Builder, fmt::JournalPrefix};

let mut builder = Builder::new();
builder.format_journal_prefix(JournalPrefix::Auto);    // default
builder.format_journal_prefix(JournalPrefix::Enable);  // always prefix
builder.format_journal_prefix(JournalPrefix::Disable); // never prefix
  • Auto (default): enables prefixes when JOURNAL_STREAM is set, resolved once at logger construction
  • Enable: always prepend <N>
  • Disable: never prepend

Priority mapping

Level Prefix Syslog
Error <3> LOG_ERR
Warn <4> LOG_WARNING
Info <6> LOG_INFO
Debug/Trace <7> LOG_DEBUG

Changes

  • src/fmt/mod.rs: Added JournalPrefix enum, journal_prefix bool field on ConfigurableFormat, resolution in fmt::Builder::build(), and write_journal_prefix() in the formatter
  • src/logger.rs: Added Builder::format_journal_prefix() method
  • Made use log::Level unconditional (was behind #[cfg(feature = "color")])

When JOURNAL_STREAM is set, log lines are prefixed with <N> (syslog
priority) so journald picks up the correct severity. Controlled via
Builder::format_journal_prefix() with Auto (default), Enable, or
Disable. Auto resolves JOURNAL_STREAM once at logger construction.
@epage
Copy link
Copy Markdown
Contributor

epage commented May 21, 2026

Note that we have an issue at #349 for this where the design is being worked through.

Independent of that, our contribution quality asks for people to work designs out in issues before posting PRs.

As this doesn't match an agreed to design, I'm going to close this for now.

@epage epage closed this May 21, 2026
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