From 17a7450452979202b7627347997125880a3459e1 Mon Sep 17 00:00:00 2001 From: adz Date: Wed, 30 Aug 2023 12:56:39 +0200 Subject: [PATCH 1/3] Configure env_logger manually --- aquadoggo_cli/src/main.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/aquadoggo_cli/src/main.rs b/aquadoggo_cli/src/main.rs index af5b6b692..67608dbe7 100644 --- a/aquadoggo_cli/src/main.rs +++ b/aquadoggo_cli/src/main.rs @@ -8,18 +8,24 @@ use std::convert::TryInto; use anyhow::Context; use aquadoggo::{AllowList, Configuration, Node}; -use log::warn; +use env_logger::WriteStyle; +use log::{warn, LevelFilter}; use crate::config::{load_config, print_config}; use crate::key_pair::{generate_ephemeral_key_pair, generate_or_load_key_pair}; #[tokio::main] async fn main() -> anyhow::Result<()> { - env_logger::init(); - // 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 + let mut builder = env_logger::Builder::new(); + builder + .filter(Some("aquadoggo"), LevelFilter::Info) + .write_style(WriteStyle::Always) + .init(); + // Convert to `aquadoggo` configuration format and check for invalid inputs let node_config = config .clone() From 158513156b193a3a82eda17132b57dbb763b982d Mon Sep 17 00:00:00 2001 From: adz Date: Wed, 30 Aug 2023 14:40:16 +0200 Subject: [PATCH 2/3] Set log verbosity through config API, scope it to aquadoggo by default --- aquadoggo_cli/src/config.rs | 13 +++++++++++++ aquadoggo_cli/src/main.rs | 12 +++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) 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 From 49c4f3ab52ad7194a35edf1b694296fb9d92ae82 Mon Sep 17 00:00:00 2001 From: adz Date: Wed, 30 Aug 2023 14:41:15 +0200 Subject: [PATCH 3/3] Add entry to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb9e61724..1cc6f81c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Rework networking service [#502](https://github.com/p2panda/aquadoggo/pull/502) - Deduplicate peer connections when initiating replication sessions [#525](https://github.com/p2panda/aquadoggo/pull/525) - Improve consistency and documentation of configuration API [#528](https://github.com/p2panda/aquadoggo/pull/528) +- Improve log level config and user interface [#539](https://github.com/p2panda/aquadoggo/pull/539) ### Fixed