diff --git a/aquadoggo_cli/src/config.rs b/aquadoggo_cli/src/config.rs index f6e3ab806..b0f42f6a3 100644 --- a/aquadoggo_cli/src/config.rs +++ b/aquadoggo_cli/src/config.rs @@ -220,6 +220,17 @@ struct Cli { )] #[serde(skip_serializing_if = "Option::is_none")] relay_mode: Option, + + /// Set log verbosity. Use this for learning more about how your node behaves or for debugging. + /// + /// Possible log levels are: ERROR, WARN, INFO, DEBUG, TRACE. They are scoped to "aquadoggo" by + /// default. + /// + /// If you want to adjust the scope for deeper inspection use a filter value, for example + /// "=TRACE" for logging _everything_ or "aquadoggo=INFO,libp2p=DEBUG" etc. + #[arg(short = 'l', long, value_name = "LEVEL")] + #[serde(skip_serializing_if = "Option::is_none")] + log_level: Option, } /// Clap converts wildcard symbols from command line arguments (for example --supported-schema-ids @@ -250,6 +261,7 @@ where /// Configuration derived from environment variables and .toml file. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Configuration { + pub log_level: String, pub allow_schema_ids: UncheckedAllowList, pub database_url: String, pub database_max_connections: u32, @@ -268,6 +280,7 @@ pub struct Configuration { impl Default for Configuration { fn default() -> Self { Self { + log_level: "off".into(), allow_schema_ids: UncheckedAllowList::Wildcard, database_url: "sqlite::memory:".into(), database_max_connections: 32, diff --git a/aquadoggo_cli/src/main.rs b/aquadoggo_cli/src/main.rs index 67608dbe7..d02d22735 100644 --- a/aquadoggo_cli/src/main.rs +++ b/aquadoggo_cli/src/main.rs @@ -5,6 +5,7 @@ mod key_pair; mod utils; use std::convert::TryInto; +use std::str::FromStr; use anyhow::Context; use aquadoggo::{AllowList, Configuration, Node}; @@ -19,12 +20,13 @@ async fn main() -> anyhow::Result<()> { // Load configuration from command line arguments, environment variables and .toml file let (config_file_path, config) = load_config().context("Could not load configuration")?; - // Configure log level + // Set log verbosity based on config. By default scope it always to the "aquadoggo" module. let mut builder = env_logger::Builder::new(); - builder - .filter(Some("aquadoggo"), LevelFilter::Info) - .write_style(WriteStyle::Always) - .init(); + let builder = match LevelFilter::from_str(&config.log_level) { + Ok(log_level) => builder.filter(Some("aquadoggo"), log_level), + Err(_) => builder.parse_filters(&config.log_level), + }; + builder.write_style(WriteStyle::Always).init(); // Convert to `aquadoggo` configuration format and check for invalid inputs let node_config = config