From: Ikeh Celestine Chukwudi Date: Wed, 14 Oct 2026 20:34:39 +0000 (+0100) Subject: fix(log): show warnings by default X-Git-Url: http://internal-gitweb-vhost/-client-interface/%22https:/implementors/enum.HexToArrayError.html?a=commitdiff_plain;h=33808beef16f9861fa9bf252bcb59affe6d3d981;p=bdk-cli fix(log): show warnings by default env_logger only shows errors when RUST_LOG is unset, so every warn!, including the mainnet notice, was hidden from users. Default the filter to warn while keeping RUST_LOG as an override, and add tests for both cases. Fixes #352 --- diff --git a/src/main.rs b/src/main.rs index 06e3ea2..d13bf8a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,7 @@ use clap::{CommandFactory, Parser}; #[tokio::main] async fn main() { - env_logger::init(); + env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init(); let cli_opts: CliOpts = CliOpts::parse(); let network = &cli_opts.network; diff --git a/tests/integration/init.rs b/tests/integration/init.rs index 120341a..12086ff 100644 --- a/tests/integration/init.rs +++ b/tests/integration/init.rs @@ -120,6 +120,30 @@ mod test_wallets { .stderr(predicate::str::contains("No wallets configured yet.")); } + #[test] + fn test_mainnet_warning_shown_by_default() { + let temp_dir = TempDir::new().unwrap(); + let cli = BdkCli::new("bitcoin", Some(temp_dir.path().to_path_buf())); + + cli.cmd("wallets", &[]) + .env_remove("RUST_LOG") + .assert() + .stderr(predicate::str::contains( + "not currently recommended for use on Bitcoin mainnet", + )); + } + + #[test] + fn test_mainnet_warning_hidden_with_rust_log_error() { + let temp_dir = TempDir::new().unwrap(); + let cli = BdkCli::new("bitcoin", Some(temp_dir.path().to_path_buf())); + + cli.cmd("wallets", &[]) + .env("RUST_LOG", "error") + .assert() + .stderr(predicate::str::contains("not currently recommended").not()); + } + #[cfg(feature = "rpc")] #[test] fn test_list_wallets_with_entries() {