From b31fbde1593f0a24b5b9f75f89e3d1593934fc15 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Mon, 29 Apr 2024 15:59:17 +0200 Subject: [PATCH] node: Add `log` to node config --- radicle-cli/examples/rad-config.md | 1 + radicle-httpd/src/api/v1/profile.rs | 1 + radicle-node/src/main.rs | 13 ++++++------- radicle/src/node/config.rs | 10 ++++++++++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/radicle-cli/examples/rad-config.md b/radicle-cli/examples/rad-config.md index 15797643..b6dc7356 100644 --- a/radicle-cli/examples/rad-config.md +++ b/radicle-cli/examples/rad-config.md @@ -28,6 +28,7 @@ $ rad config "externalAddresses": [], "tor": null, "network": "main", + "log": "INFO", "relay": true, "limits": { "routingMaxSize": 1000, diff --git a/radicle-httpd/src/api/v1/profile.rs b/radicle-httpd/src/api/v1/profile.rs index 57d702fe..2307a0b5 100644 --- a/radicle-httpd/src/api/v1/profile.rs +++ b/radicle-httpd/src/api/v1/profile.rs @@ -91,6 +91,7 @@ mod routes { "externalAddresses": [], "tor": null, "network": "main", + "log": "INFO", "relay": true, "limits": { "routingMaxSize": 1000, diff --git a/radicle-node/src/main.rs b/radicle-node/src/main.rs index 5ca29ab5..3f4e8c87 100644 --- a/radicle-node/src/main.rs +++ b/radicle-node/src/main.rs @@ -41,7 +41,7 @@ Options struct Options { config: Option, listen: Vec, - log: log::Level, + log: Option, force: bool, } @@ -53,7 +53,7 @@ impl Options { let mut listen = Vec::new(); let mut config = None; let mut force = false; - let mut log = log::Level::Info; + let mut log = None; while let Some(arg) = parser.next()? { match arg { @@ -70,7 +70,7 @@ impl Options { listen.push(addr); } Long("log") => { - log = parser.value()?.parse()?; + log = Some(parser.value()?.parse()?); } Long("help") | Short('h') => { println!("{HELP_MSG}"); @@ -96,8 +96,10 @@ impl Options { fn execute() -> anyhow::Result<()> { let home = profile::home()?; let options = Options::from_env()?; + let config = options.config.unwrap_or_else(|| home.config()); + let mut config = profile::Config::load(&config)?; - logger::init(options.log)?; + logger::init(options.log.unwrap_or(config.node.log))?; log::info!(target: "node", "Starting node.."); log::info!(target: "node", "Version {} ({})", env!("RADICLE_VERSION"), env!("GIT_HEAD")); @@ -109,9 +111,6 @@ fn execute() -> anyhow::Result<()> { log::info!(target: "node", "Node ID is {}", signer.public_key()); - let config = options.config.unwrap_or_else(|| home.config()); - let mut config = profile::Config::load(&config)?; - // Add the preferred seeds as persistent peers so that we reconnect to them automatically. config.node.connect.extend(config.preferred_seeds); diff --git a/radicle/src/node/config.rs b/radicle/src/node/config.rs index d95d4a3b..27b9b2c0 100644 --- a/radicle/src/node/config.rs +++ b/radicle/src/node/config.rs @@ -272,6 +272,10 @@ pub struct Config { /// Peer-to-peer network. #[serde(default)] pub network: Network, + /// Log level. + #[serde(default = "defaults::log")] + #[serde(with = "crate::serde_ext::string")] + pub log: log::Level, /// Whether or not our node should relay inventories. #[serde(default = "crate::serde_ext::bool::yes")] pub relay: bool, @@ -309,6 +313,7 @@ impl Config { relay: true, limits: Limits::default(), workers: DEFAULT_WORKERS, + log: defaults::log(), policy: Policy::default(), scope: Scope::default(), } @@ -336,4 +341,9 @@ mod defaults { pub fn workers() -> usize { super::DEFAULT_WORKERS } + + /// Log level. + pub fn log() -> log::Level { + log::Level::Info + } }