From ea660115ed7fef307997e6d32c541f3963af0e61 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 28 Oct 2026 19:02:59 +0100 Subject: log to journal sanely --- src/config/mod.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/config/mod.rs') diff --git a/src/config/mod.rs b/src/config/mod.rs index 9210922..5837d1e 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -109,6 +109,13 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[ None, "HTTP API users (from htpasswd) who may write protocol data under /store/_continuum (remake records, members, forget records), e.g. to repair a stuck remake. Such writes act on the whole swarm and are logged. Epoch metadata and the swarm ID are never writable.", ), + option( + "log-format", + Kind::Text, + "auto|text|journal", + Some("auto"), + "How log lines look: `text` (timestamped), `journal` (for systemd's journal: no timestamp or colours, the level as each line's priority, for journalctl -p), or `auto`: journal when stdout goes to the journal, else text.", + ), option( "log-raw-ids", Kind::Flag, @@ -390,6 +397,8 @@ pub(crate) struct Settings { pub(crate) protocol_writers: Vec, #[serde(default)] pub(crate) debug_api: bool, + #[serde(default = "default_log_format")] + pub(crate) log_format: String, #[serde(default)] pub(crate) log_raw_ids: bool, #[serde(default)] @@ -499,6 +508,9 @@ pub(crate) const TRANSPORTS: &[(&str, bool)] = &[ ("libp2p", cfg!(feature = "libp2p")), ("tor", cfg!(feature = "tor")), ]; +fn default_log_format() -> String { + "auto".to_owned() +} fn default_tor_port() -> u16 { 9662 } @@ -535,6 +547,13 @@ impl Settings { } fn check(&self) -> Result<()> { + if crate::logging::LogFormat::parse(&self.log_format).is_none() { + bail!( + "log-format {:?}: one of {}", + self.log_format, + crate::logging::LogFormat::NAMES.join(", ") + ); + } if let Some(url) = &self.mycelium_rest_url { url::Url::parse(url).with_context(|| format!("mycelium-rest-url {url:?}"))?; } -- cgit v1.3.1