From 9b1e1d20e13136e68d99fe3fd3c04e969fba7fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Wed, 22 Jul 2026 10:56:56 +0200 Subject: [PATCH] Respect RUST_LOG in default httpd logger Wire up an EnvFilter that reads RUST_LOG, defaulting to "info", and enable the env-filter feature unconditionally. --- crates/radicle-httpd/Cargo.toml | 3 +-- crates/radicle-httpd/radicle-httpd.1.adoc | 7 +++++++ crates/radicle-httpd/src/lib.rs | 6 +++++- crates/radicle-httpd/src/main.rs | 5 +++++ crates/radicle-search/src/main.rs | 4 +++- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/crates/radicle-httpd/Cargo.toml b/crates/radicle-httpd/Cargo.toml index f6c1f2185..0ff571382 100644 --- a/crates/radicle-httpd/Cargo.toml +++ b/crates/radicle-httpd/Cargo.toml @@ -13,7 +13,6 @@ build = "build.rs" default = [] logfmt = [ "tracing-logfmt", - "tracing-subscriber/env-filter" ] [[bin]] @@ -46,7 +45,7 @@ tokio-util = { version = "0.7.18", default-features = false, features = ["io"] } tower-http = { version = "0.6.6", default-features = false, features = ["trace", "cors", "set-header", "decompression-full"] } tracing.workspace = true tracing-logfmt = { version = "0.3.5", optional = true } -tracing-subscriber.workspace = true +tracing-subscriber = { workspace = true, features = ["env-filter"] } url = { version = "2.5.4", features = ["serde"] } uuid = { version = "1.13.1", features = ["serde"] } diff --git a/crates/radicle-httpd/radicle-httpd.1.adoc b/crates/radicle-httpd/radicle-httpd.1.adoc index 3be21bc30..913b20914 100644 --- a/crates/radicle-httpd/radicle-httpd.1.adoc +++ b/crates/radicle-httpd/radicle-httpd.1.adoc @@ -20,6 +20,13 @@ A Radicle HTTP daemon exposing a JSON HTTP API that allows someone to browse loc repositories on a Radicle node via their web browser. This manual page is a placeholder to point you at the *--help* option. +== Environment + +*RUST_LOG*:: + Sets the log level. Accepts standard `tracing`/`env_logger`-style directives, + for example `RUST_LOG=warn` or `RUST_LOG=radicle_httpd=debug`. Defaults to + `info` when unset. + == SEE ALSO == *rad*(1) diff --git a/crates/radicle-httpd/src/lib.rs b/crates/radicle-httpd/src/lib.rs index ec0d03a18..aa2b0c073 100644 --- a/crates/radicle-httpd/src/lib.rs +++ b/crates/radicle-httpd/src/lib.rs @@ -237,9 +237,13 @@ pub mod logger { #[cfg(not(feature = "logfmt"))] pub fn subscriber() -> impl tracing::Subscriber { + use tracing_subscriber::EnvFilter; + tracing_subscriber::FmtSubscriber::builder() .with_target(false) - .with_max_level(tracing::Level::DEBUG) + .with_env_filter( + EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")), + ) .finish() } } diff --git a/crates/radicle-httpd/src/main.rs b/crates/radicle-httpd/src/main.rs index 59d3dff17..b06a3382a 100644 --- a/crates/radicle-httpd/src/main.rs +++ b/crates/radicle-httpd/src/main.rs @@ -29,6 +29,11 @@ Options --cache Max amount of items in cache for /tree endpoints (default: 100) --version, -v Print program version --help, -h Print help + +Environment + + RUST_LOG Set the log level (e.g. RUST_LOG=warn, or + RUST_LOG=radicle_httpd=debug). Defaults to "info". "#; #[tokio::main] diff --git a/crates/radicle-search/src/main.rs b/crates/radicle-search/src/main.rs index 84bc95472..481ca1581 100644 --- a/crates/radicle-search/src/main.rs +++ b/crates/radicle-search/src/main.rs @@ -24,6 +24,8 @@ Environment RADICLE_SEARCH_RESCAN_SECS Periodic full rescan interval in seconds (default: 3600) RADICLE_SEARCH_RECONNECT_BACKOFF_SECS Reconnect delay after a dropped event stream (default: 5) RAD_HOME, RAD_SOCKET Standard Radicle paths + RUST_LOG Log level, e.g. RUST_LOG=warn or + RUST_LOG=radicle_search=debug (default: info) "#; #[tokio::main] @@ -43,7 +45,7 @@ async fn main() { fn init_tracing() { let filter = tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("radicle_search=info,info")); + .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")); tracing_subscriber::fmt().with_env_filter(filter).init(); }