]> Untitled Git - bdk-cli/commitdiff
fix(log): show warnings by default
authorIkeh Celestine Chukwudi <Chukwudi.ikeh.232330@unn.edu.ng>
Wed, 14 Oct 2026 20:34:39 +0000 (21:34 +0100)
committerIkeh Celestine Chukwudi <Chukwudi.ikeh.232330@unn.edu.ng>
Wed, 14 Oct 2026 20:34:39 +0000 (21:34 +0100)
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

src/main.rs
tests/integration/init.rs

index 06e3ea2469dfe4df4b02305f3b6c4f11a0e54c68..d13bf8a9ac1486dc13b4f2892cce456d566cd33b 100644 (file)
@@ -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;
index 120341abe7c79aeed501af38993db707293770b3..12086ff67ab8b55e9dbf92069588dc0d0de4a411 100644 (file)
@@ -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() {