diff --git a/Cargo.lock b/Cargo.lock index c67b0bfa..458e4574 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1618,6 +1618,7 @@ version = "0.23.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ + "log", "once_cell", "ring", "rustls-pki-types", @@ -2074,19 +2075,20 @@ checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" -version = "0.1.40" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" dependencies = [ + "log", "pin-project-lite", "tracing-core", ] [[package]] name = "tracing-core" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" dependencies = [ "once_cell", ] @@ -2542,6 +2544,7 @@ dependencies = [ "reqwest", "roff", "rpassword", + "rustls", "ruzstd", "serde", "serde-transcode", @@ -2553,6 +2556,7 @@ dependencies = [ "termcolor", "time", "tokio", + "tracing", "unicode-width", "url", ] diff --git a/Cargo.toml b/Cargo.toml index 05bfafab..0cadc32d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ dirs = "5.0" encoding_rs = "0.8.28" encoding_rs_io = "0.1.7" flate2 = "1.0.22" +# Add "tracing" feature to hyper once it stabilizes hyper = { version = "1.2", default-features = false } indicatif = "0.17" jsonxf = "1.1.0" @@ -52,6 +53,11 @@ ruzstd = { version = "0.7", default-features = false, features = ["std"]} env_logger = { version = "0.11.3", default-features = false, features = ["color", "auto-color", "humantime"] } log = "0.4.21" +# Enable logging in transitive dependencies. +# The rustls version number should be kept in sync with hyper/reqwest. +rustls = { version = "0.23.14", optional = true, default-features = false, features = ["logging"] } +tracing = { version = "0.1.41", default-features = false, features = ["log"] } + [dependencies.reqwest] version = "0.12.3" default-features = false @@ -85,7 +91,7 @@ http-body-util = "0.1.1" [features] default = ["online-tests", "rustls", "network-interface"] native-tls = ["reqwest/native-tls", "reqwest/native-tls-alpn"] -rustls = ["reqwest/rustls-tls", "reqwest/rustls-tls-webpki-roots", "reqwest/rustls-tls-native-roots"] +rustls = ["reqwest/rustls-tls", "reqwest/rustls-tls-webpki-roots", "reqwest/rustls-tls-native-roots", "dep:rustls"] # To be used by platforms that don't support binding to interface via SO_BINDTODEVICE # Ideally, this would be auto-disabled on platforms that don't need it diff --git a/src/main.rs b/src/main.rs index 6061e122..68526a22 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,6 +73,7 @@ fn main() { log::debug!("{args:#?}"); let native_tls = args.native_tls; + let bin_name = args.bin_name.clone(); match run(args) { Ok(exit_code) => { @@ -80,7 +81,7 @@ fn main() { } Err(err) => { log::debug!("{err:#?}"); - log::error!("{err:?}"); + eprintln!("{bin_name}: error: {err:?}"); let msg = err.root_cause().to_string(); if native_tls && msg == "invalid minimum TLS version for backend" { eprintln!(); diff --git a/tests/cases/logging.rs b/tests/cases/logging.rs index da2609e2..4c32e276 100644 --- a/tests/cases/logging.rs +++ b/tests/cases/logging.rs @@ -124,3 +124,23 @@ fn warning_for_non_utf8_redirect() { .assert() .stderr("xh: warning: Redirect to invalid URL: \"\\xff\"\n"); } + +/// This test should fail if rustls's version gets out of sync in Cargo.toml. +#[cfg(feature = "rustls")] +#[test] +fn rustls_emits_logs() { + let mut server = server::http(|_req| async move { + unreachable!(); + }); + server.disable_hit_checks(); + let cmd = get_command() + .arg("--debug") + .arg(server.base_url().replace("http://", "https://")) + .env_remove("RUST_LOG") + .assert() + .failure(); + + assert!(std::str::from_utf8(&cmd.get_output().stderr) + .unwrap() + .contains("rustls::")); +}