From 42a81e8695330a57ea7a51de69e71a893e5d8db9 Mon Sep 17 00:00:00 2001 From: neuronull <9162534+neuronull@users.noreply.github.com> Date: Wed, 19 Nov 2025 10:31:05 -0700 Subject: [PATCH 1/3] Replace log with tracing for ios and android uniffi --- Cargo.lock | 70 +++++++---------- crates/bitwarden-uniffi/Cargo.toml | 8 +- .../bitwarden-uniffi/src/android_support.rs | 15 ++-- crates/bitwarden-uniffi/src/lib.rs | 75 +++++++++++++++---- 4 files changed, 100 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2dd888421..f60ef21d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,20 +97,9 @@ checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" [[package]] name = "android_log-sys" -version = "0.3.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" - -[[package]] -name = "android_logger" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f39be698127218cca460cb624878c9aa4e2b47dba3b277963d2bf00bad263b" -dependencies = [ - "android_log-sys", - "env_filter", - "log", -] +checksum = "85965b6739a430150bdd138e2374a98af0c3ee0d030b3bb7fc3bddff58d0102e" [[package]] name = "android_system_properties" @@ -893,7 +882,6 @@ dependencies = [ name = "bitwarden-uniffi" version = "0.1.0" dependencies = [ - "android_logger", "async-trait", "bitwarden-collections", "bitwarden-core", @@ -909,13 +897,14 @@ dependencies = [ "bitwarden-uniffi-error", "bitwarden-vault", "chrono", - "env_logger", "jni", "libloading", - "log", - "oslog", "rustls-platform-verifier", "thiserror 2.0.12", + "tracing", + "tracing-android", + "tracing-oslog", + "tracing-subscriber", "uniffi", "uuid", ] @@ -1762,19 +1751,6 @@ dependencies = [ "syn", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown 0.14.5", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "data-encoding" version = "2.9.0" @@ -3418,17 +3394,6 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - [[package]] name = "owo-colors" version = "4.2.1" @@ -5313,6 +5278,17 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-android" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12612be8f868a09c0ceae7113ff26afe79d81a24473a393cb9120ece162e86c0" +dependencies = [ + "android_log-sys", + "tracing", + "tracing-subscriber", +] + [[package]] name = "tracing-attributes" version = "0.1.30" @@ -5355,6 +5331,18 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-oslog" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76902d2a8d5f9f55a81155c08971734071968c90f2d9bfe645fe700579b2950" +dependencies = [ + "cc", + "cfg-if", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "tracing-subscriber" version = "0.3.20" diff --git a/crates/bitwarden-uniffi/Cargo.toml b/crates/bitwarden-uniffi/Cargo.toml index 82aa7a7bb..935fac93b 100644 --- a/crates/bitwarden-uniffi/Cargo.toml +++ b/crates/bitwarden-uniffi/Cargo.toml @@ -34,14 +34,14 @@ bitwarden-state = { workspace = true, features = ["uniffi"] } bitwarden-uniffi-error = { workspace = true } bitwarden-vault = { workspace = true, features = ["uniffi"] } chrono = { workspace = true, features = ["std"] } -env_logger = "0.11.1" -log = { workspace = true } thiserror = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } uniffi = { workspace = true } uuid = { workspace = true } [target.'cfg(target_os = "android")'.dependencies] -android_logger = "0.15" +tracing-android = "0.2.0" # The use of rustls-platform-verifier requires some extra support to communicate with the Android platform jni = ">=0.21, <0.22" @@ -49,7 +49,7 @@ libloading = ">=0.8.1, <0.9" rustls-platform-verifier = "0.6.0" [target.'cfg(target_os = "ios")'.dependencies] -oslog = "0.2.0" +tracing-oslog = "0.3.0" [build-dependencies] uniffi = { workspace = true, features = ["build"] } diff --git a/crates/bitwarden-uniffi/src/android_support.rs b/crates/bitwarden-uniffi/src/android_support.rs index 12ebc38df..b65df94c2 100644 --- a/crates/bitwarden-uniffi/src/android_support.rs +++ b/crates/bitwarden-uniffi/src/android_support.rs @@ -1,6 +1,7 @@ use std::{error::Error, sync::OnceLock}; use jni::sys::{JavaVM, jint, jsize}; +use tracing::{error, info}; pub static JAVA_VM: OnceLock = OnceLock::new(); @@ -9,7 +10,7 @@ pub static JAVA_VM: OnceLock = OnceLock::new(); #[allow(non_snake_case)] #[unsafe(no_mangle)] pub extern "system" fn JNI_OnLoad(vm_ptr: jni::JavaVM, _reserved: *mut std::ffi::c_void) -> jint { - log::info!("JNI_OnLoad initializing"); + info!("JNI_OnLoad initializing"); JAVA_VM.get_or_init(|| vm_ptr); jni::sys::JNI_VERSION_1_6 } @@ -18,25 +19,25 @@ pub fn init() { fn init_inner() -> Result<(), Box> { let jvm = match JAVA_VM.get() { Some(jvm) => { - log::info!("JavaVM already initialized"); + info!("JavaVM already initialized"); jvm } None => { - log::info!("JavaVM not initialized, initializing now"); + info!("JavaVM not initialized, initializing now"); let jvm = java_vm()?; JAVA_VM.get_or_init(|| jvm) } }; let mut env = jvm.attach_current_thread_permanently()?; - log::info!("Initializing Android verifier"); + info!("Initializing Android verifier"); init_verifier(&mut env)?; - log::info!("SDK Android support initialized"); + info!("SDK Android support initialized"); Ok(()) } - if let Err(e) = init_inner() { - log::error!("Failed to initialize Android support: {:#?}", e); + if let Err(error) = init_inner() { + error!(%error, "Failed to initialize Android support"); } } diff --git a/crates/bitwarden-uniffi/src/lib.rs b/crates/bitwarden-uniffi/src/lib.rs index 9e2244dd8..f16325763 100644 --- a/crates/bitwarden-uniffi/src/lib.rs +++ b/crates/bitwarden-uniffi/src/lib.rs @@ -2,7 +2,7 @@ uniffi::setup_scaffolding!(); -use std::sync::Arc; +use std::sync::{Arc, Once}; use auth::AuthClient; use bitwarden_core::{ClientSettings, client::internal::ClientManagedTokens}; @@ -111,22 +111,65 @@ impl Client { } } +static INIT: Once = Once::new(); + fn init_logger() { - #[cfg(not(any(target_os = "android", target_os = "ios")))] - let _ = env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")) - .try_init(); - - #[cfg(target_os = "ios")] - let _ = oslog::OsLogger::new("com.8bit.bitwarden") - .level_filter(log::LevelFilter::Info) - .init(); - - #[cfg(target_os = "android")] - android_logger::init_once( - android_logger::Config::default() - .with_tag("com.bitwarden.sdk") - .with_max_level(log::LevelFilter::Info), - ); + use tracing_subscriber::{EnvFilter, layer::SubscriberExt as _, util::SubscriberInitExt as _}; + + INIT.call_once(|| { + // the log level prioritization is determined by: + // 1. if RUST_LOG is detected at runtime + // 2. if RUST_LOG is provided at compile time + // 3. default to INFO + let filter = EnvFilter::builder() + .with_default_directive( + option_env!("RUST_LOG") + .unwrap_or("info") + .parse() + .expect("should provide valid log level at compile time."), + ) + .from_env_lossy(); + + let fmtlayer = tracing_subscriber::fmt::layer() + .with_ansi(true) + .with_file(true) + .with_line_number(true) + .with_target(true) + .pretty(); + + #[cfg(target_os = "ios")] + { + const TAG: &str = "com.8bit.bitwarden"; + + tracing_subscriber::registry() + .with(fmtlayer) + .with(filter) + .with(tracing_oslog::OsLogger::new(TAG, "default")) + .init(); + } + + #[cfg(target_os = "android")] + { + const TAG: &str = "com.bitwarden.sdk"; + + tracing_subscriber::registry() + .with(fmtlayer) + .with(filter) + .with( + tracing_android::layer(TAG) + .expect("initialization of android logcat tracing layer"), + ) + .init(); + } + + #[cfg(not(any(target_os = "android", target_os = "ios")))] + { + tracing_subscriber::registry() + .with(fmtlayer) + .with(filter) + .init(); + } + }); } /// Setup the error converter to ensure conversion errors don't cause panics From 143e39f778a11845801140f862ab89c13b6a982a Mon Sep 17 00:00:00 2001 From: neuronull <9162534+neuronull@users.noreply.github.com> Date: Fri, 21 Nov 2025 12:21:09 -0700 Subject: [PATCH 2/3] Replace log with tracing --- Cargo.lock | 14 +++++------ Cargo.toml | 1 - bitwarden_license/bitwarden-sm/Cargo.toml | 2 +- bitwarden_license/bitwarden-sm/src/error.rs | 4 ++-- crates/bitwarden-core/Cargo.toml | 2 +- .../auth/api/request/access_token_request.rs | 4 ++-- .../src/auth/api/request/api_token_request.rs | 4 ++-- .../api/request/auth_request_token_request.rs | 4 ++-- .../api/request/password_token_request.rs | 4 ++-- .../bitwarden-core/src/auth/login/password.rs | 4 ++-- .../src/client/encryption_settings.rs | 4 ++-- crates/bitwarden-core/src/client/internal.rs | 4 ++-- .../src/key_management/crypto.rs | 6 ++--- .../src/platform/get_user_api_key.rs | 4 ++-- crates/bitwarden-fido/Cargo.toml | 2 +- crates/bitwarden-fido/src/authenticator.rs | 18 +++++++------- crates/bitwarden-fido/src/crypto.rs | 6 ++--- crates/bitwarden-ipc/Cargo.toml | 2 +- crates/bitwarden-ipc/src/ipc_client.rs | 18 +++++++------- crates/bitwarden-threading/Cargo.toml | 2 +- .../src/thread_bound_runner.rs | 2 +- crates/bw/Cargo.toml | 4 ++-- crates/bw/src/auth/login.rs | 16 ++++++------- crates/bw/src/main.rs | 24 ++++++++++++++++--- 24 files changed, 86 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f60ef21d3..ac525cbf1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -550,7 +550,6 @@ dependencies = [ "bitwarden-uuid", "chrono", "getrandom 0.2.16", - "log", "rand 0.8.5", "rand_chacha 0.3.1", "reqwest", @@ -564,6 +563,7 @@ dependencies = [ "serde_repr", "thiserror 2.0.12", "tokio", + "tracing", "tsify", "uniffi", "uuid", @@ -699,7 +699,6 @@ dependencies = [ "chrono", "coset", "itertools 0.14.0", - "log", "p256", "passkey", "passkey-client", @@ -707,6 +706,7 @@ dependencies = [ "serde", "serde_json", "thiserror 2.0.12", + "tracing", "uniffi", "uuid", ] @@ -741,11 +741,11 @@ dependencies = [ "bitwarden-threading", "erased-serde", "js-sys", - "log", "serde", "serde_json", "thiserror 2.0.12", "tokio", + "tracing", "tsify", "uuid", "wasm-bindgen", @@ -796,12 +796,12 @@ dependencies = [ "bitwarden-core", "bitwarden-crypto", "chrono", - "log", "schemars 1.0.0", "serde", "serde_json", "thiserror 2.0.12", "tokio", + "tracing", "uuid", "validator", "wiremock", @@ -866,12 +866,12 @@ dependencies = [ "console_error_panic_hook", "gloo-timers", "js-sys", - "log", "serde", "thiserror 2.0.12", "tokio", "tokio-test", "tokio-util", + "tracing", "tsify", "wasm-bindgen", "wasm-bindgen-futures", @@ -1097,15 +1097,15 @@ dependencies = [ "clap", "clap_complete", "color-eyre", - "env_logger", "erased-serde", "inquire 0.9.1", - "log", "serde", "serde_json", "serde_yaml", "thiserror 2.0.12", "tokio", + "tracing", + "tracing-subscriber", "uuid", "wiremock", ] diff --git a/Cargo.toml b/Cargo.toml index 9e319870c..e6d414f8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,7 +58,6 @@ data-encoding = ">=2.0, <3" ed25519-dalek = { version = ">=2.1.1, <=2.2.0" } futures = ">=0.3.31, <0.4" js-sys = { version = ">=0.3.72, <0.4" } -log = ">=0.4.18, <0.5" proc-macro2 = ">=1.0.89, <2" quote = ">=1.0.37, <2" reqwest = { version = ">=0.12.5, <0.13", features = [ diff --git a/bitwarden_license/bitwarden-sm/Cargo.toml b/bitwarden_license/bitwarden-sm/Cargo.toml index 0eed312d1..efb50af5a 100644 --- a/bitwarden_license/bitwarden-sm/Cargo.toml +++ b/bitwarden_license/bitwarden-sm/Cargo.toml @@ -18,11 +18,11 @@ bitwarden-api-api = { workspace = true } bitwarden-core = { workspace = true, features = ["secrets"] } bitwarden-crypto = { workspace = true } chrono = { workspace = true } -log = { workspace = true } schemars = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } +tracing = { workspace = true } uuid = { workspace = true } validator = { workspace = true } diff --git a/bitwarden_license/bitwarden-sm/src/error.rs b/bitwarden_license/bitwarden-sm/src/error.rs index 48626850a..64d9e6770 100644 --- a/bitwarden_license/bitwarden-sm/src/error.rs +++ b/bitwarden_license/bitwarden-sm/src/error.rs @@ -1,6 +1,6 @@ use bitwarden_api_api::apis::Error as ApiApisError; -use log::debug; use thiserror::Error; +use tracing::debug; use validator::ValidationErrors; #[derive(Debug, thiserror::Error)] @@ -45,7 +45,7 @@ pub fn validate_only_whitespaces(value: &str) -> Result<(), validator::Validatio impl From for ValidationError { fn from(e: ValidationErrors) -> Self { - debug!("Validation errors: {e:#?}"); + debug!(?e, "Validation errors"); for (field_name, errors) in e.field_errors() { for error in errors { match error.code.as_ref() { diff --git a/crates/bitwarden-core/Cargo.toml b/crates/bitwarden-core/Cargo.toml index 86c184a90..701af9a13 100644 --- a/crates/bitwarden-core/Cargo.toml +++ b/crates/bitwarden-core/Cargo.toml @@ -49,7 +49,6 @@ bitwarden-uuid = { workspace = true } chrono = { workspace = true, features = ["std"] } # We don't use this directly (it's used by rand), but we need it here to enable WASM support getrandom = { version = ">=0.2.9, <0.3", features = ["js"] } -log = { workspace = true } rand = ">=0.8.5, <0.9" reqwest = { workspace = true } schemars = { workspace = true } @@ -59,6 +58,7 @@ serde_json = { workspace = true } serde_qs = { workspace = true } serde_repr = { workspace = true } thiserror = { workspace = true } +tracing = { workspace = true } tsify = { workspace = true, optional = true } uniffi = { workspace = true, optional = true, features = ["tokio"] } uuid = { workspace = true } diff --git a/crates/bitwarden-core/src/auth/api/request/access_token_request.rs b/crates/bitwarden-core/src/auth/api/request/access_token_request.rs index cf78cbcc8..2c57c1e54 100644 --- a/crates/bitwarden-core/src/auth/api/request/access_token_request.rs +++ b/crates/bitwarden-core/src/auth/api/request/access_token_request.rs @@ -1,5 +1,5 @@ -use log::debug; use serde::{Deserialize, Serialize}; +use tracing::debug; use uuid::Uuid; use crate::{ @@ -23,7 +23,7 @@ impl AccessTokenRequest { client_secret: client_secret.to_string(), grant_type: "client_credentials".to_string(), }; - debug!("initializing {obj:?}"); + debug!(?obj, "initializing"); obj } diff --git a/crates/bitwarden-core/src/auth/api/request/api_token_request.rs b/crates/bitwarden-core/src/auth/api/request/api_token_request.rs index 83db4371e..bd2658d67 100644 --- a/crates/bitwarden-core/src/auth/api/request/api_token_request.rs +++ b/crates/bitwarden-core/src/auth/api/request/api_token_request.rs @@ -1,5 +1,5 @@ -use log::debug; use serde::{Deserialize, Serialize}; +use tracing::debug; use crate::{ auth::{api::response::IdentityTokenResponse, login::LoginError}, @@ -31,7 +31,7 @@ impl ApiTokenRequest { device_name: "firefox".to_string(), grant_type: "client_credentials".to_string(), }; - debug!("initializing {obj:?}"); + debug!(?obj, "initializing"); obj } diff --git a/crates/bitwarden-core/src/auth/api/request/auth_request_token_request.rs b/crates/bitwarden-core/src/auth/api/request/auth_request_token_request.rs index 9d210519b..d0230595f 100644 --- a/crates/bitwarden-core/src/auth/api/request/auth_request_token_request.rs +++ b/crates/bitwarden-core/src/auth/api/request/auth_request_token_request.rs @@ -1,5 +1,5 @@ -use log::debug; use serde::{Deserialize, Serialize}; +use tracing::debug; use uuid::Uuid; use crate::{ @@ -47,7 +47,7 @@ impl AuthRequestTokenRequest { auth_request_id: *auth_request_id, access_code: access_code.to_string(), }; - debug!("initializing {obj:?}"); + debug!(?obj, "initializing"); obj } diff --git a/crates/bitwarden-core/src/auth/api/request/password_token_request.rs b/crates/bitwarden-core/src/auth/api/request/password_token_request.rs index abec26ee2..6c6e55c40 100644 --- a/crates/bitwarden-core/src/auth/api/request/password_token_request.rs +++ b/crates/bitwarden-core/src/auth/api/request/password_token_request.rs @@ -1,5 +1,5 @@ -use log::debug; use serde::{Deserialize, Serialize}; +use tracing::debug; use crate::{ DeviceType, @@ -56,7 +56,7 @@ impl PasswordTokenRequest { two_factor_provider: tf.map(|t| t.provider.clone()), two_factor_remember: tf.map(|t| t.remember), }; - debug!("initializing {obj:?}"); + debug!(?obj, "initializing"); obj } diff --git a/crates/bitwarden-core/src/auth/login/password.rs b/crates/bitwarden-core/src/auth/login/password.rs index c89a0c709..95d4968ce 100644 --- a/crates/bitwarden-core/src/auth/login/password.rs +++ b/crates/bitwarden-core/src/auth/login/password.rs @@ -1,7 +1,7 @@ -#[cfg(feature = "internal")] -use log::info; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; +#[cfg(feature = "internal")] +use tracing::info; use crate::auth::{ api::response::IdentityTokenResponse, login::response::two_factor::TwoFactorProviders, diff --git a/crates/bitwarden-core/src/client/encryption_settings.rs b/crates/bitwarden-core/src/client/encryption_settings.rs index b7e1f3700..0ab5c6f08 100644 --- a/crates/bitwarden-core/src/client/encryption_settings.rs +++ b/crates/bitwarden-core/src/client/encryption_settings.rs @@ -9,9 +9,9 @@ use bitwarden_crypto::{ #[cfg(any(feature = "internal", feature = "secrets"))] use bitwarden_crypto::{KeyStore, SymmetricCryptoKey}; use bitwarden_error::bitwarden_error; -#[cfg(feature = "internal")] -use log::warn; use thiserror::Error; +#[cfg(feature = "internal")] +use tracing::warn; #[cfg(any(feature = "secrets", feature = "internal"))] use crate::OrganizationId; diff --git a/crates/bitwarden-core/src/client/internal.rs b/crates/bitwarden-core/src/client/internal.rs index dbfe7ccb7..03ff95864 100644 --- a/crates/bitwarden-core/src/client/internal.rs +++ b/crates/bitwarden-core/src/client/internal.rs @@ -194,9 +194,9 @@ impl InternalClient { #[cfg(any(feature = "internal", feature = "secrets"))] pub(crate) fn set_login_method(&self, login_method: LoginMethod) { - use log::debug; + use tracing::debug; - debug! {"setting login method: {login_method:#?}"} + debug!(?login_method, "setting login method."); *self.login_method.write().expect("RwLock is not poisoned") = Some(Arc::new(login_method)); } diff --git a/crates/bitwarden-core/src/key_management/crypto.rs b/crates/bitwarden-core/src/key_management/crypto.rs index f050cc542..57f497efe 100644 --- a/crates/bitwarden-core/src/key_management/crypto.rs +++ b/crates/bitwarden-core/src/key_management/crypto.rs @@ -672,11 +672,11 @@ pub(super) fn verify_asymmetric_keys( private_key_decryptable: true, valid_private_key: true, }, - Err(e) => { - log::debug!("User asymmetric keys verification: {e}"); + Err(error) => { + tracing::debug!(%error, "User asymmetric keys verification"); VerifyAsymmetricKeysResponse { - private_key_decryptable: !matches!(e, VerifyError::DecryptFailed(_)), + private_key_decryptable: !matches!(error, VerifyError::DecryptFailed(_)), valid_private_key: false, } } diff --git a/crates/bitwarden-core/src/platform/get_user_api_key.rs b/crates/bitwarden-core/src/platform/get_user_api_key.rs index ddd71720f..e91f6301c 100644 --- a/crates/bitwarden-core/src/platform/get_user_api_key.rs +++ b/crates/bitwarden-core/src/platform/get_user_api_key.rs @@ -16,9 +16,9 @@ use std::sync::Arc; use bitwarden_api_api::models::{ApiKeyResponseModel, SecretVerificationRequestModel}; use bitwarden_crypto::{CryptoError, HashPurpose, MasterKey}; -use log::{debug, info}; use serde::{Deserialize, Serialize}; use thiserror::Error; +use tracing::{debug, info}; use super::SecretVerificationRequest; use crate::{ @@ -48,7 +48,7 @@ pub(crate) async fn get_user_api_key( input: &SecretVerificationRequest, ) -> Result { info!("Getting Api Key"); - debug!("{input:?}"); + debug!(?input); let auth_settings = get_login_method(client)?; let config = client.internal.get_api_configurations().await; diff --git a/crates/bitwarden-fido/Cargo.toml b/crates/bitwarden-fido/Cargo.toml index 9d8637b96..6cc86ef97 100644 --- a/crates/bitwarden-fido/Cargo.toml +++ b/crates/bitwarden-fido/Cargo.toml @@ -26,7 +26,6 @@ bitwarden-vault = { workspace = true } chrono = { workspace = true } coset = ">=0.3.7, <0.4" itertools = ">=0.13.0, <0.15" -log = { workspace = true } p256 = ">=0.13.2, <0.14" passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "3b764633ebc6576c07bdd12ee14d8e5c87b494ed" } passkey-client = { git = "https://github.com/bitwarden/passkey-rs", rev = "3b764633ebc6576c07bdd12ee14d8e5c87b494ed", features = [ @@ -36,6 +35,7 @@ reqwest = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } +tracing = { workspace = true } uniffi = { workspace = true, optional = true } uuid = { workspace = true } diff --git a/crates/bitwarden-fido/src/authenticator.rs b/crates/bitwarden-fido/src/authenticator.rs index 6093142e6..27853b053 100644 --- a/crates/bitwarden-fido/src/authenticator.rs +++ b/crates/bitwarden-fido/src/authenticator.rs @@ -4,7 +4,6 @@ use bitwarden_core::Client; use bitwarden_crypto::CryptoError; use bitwarden_vault::{CipherError, CipherView, EncryptionContext}; use itertools::Itertools; -use log::error; use passkey::{ authenticator::{Authenticator, DiscoverabilitySupport, StoreInfo, UIHint, UserCheck}, types::{ @@ -13,6 +12,7 @@ use passkey::{ }, }; use thiserror::Error; +use tracing::error; use super::{ AAGUID, CheckUserOptions, CipherViewContainer, Fido2CredentialStore, Fido2UserInterface, @@ -419,8 +419,8 @@ impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> { } } - inner(self, ids, rp_id).await.map_err(|e| { - error!("Error finding credentials: {e:?}"); + inner(self, ids, rp_id).await.map_err(|error| { + error!(%error, "Error finding credentials."); VendorError::try_from(0xF0) .expect("Valid vendor error code") .into() @@ -501,8 +501,8 @@ impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> { Ok(()) } - inner(self, cred, user, rp, options).await.map_err(|e| { - error!("Error saving credential: {e:?}"); + inner(self, cred, user, rp, options).await.map_err(|error| { + error!(%error, "Error saving credential."); VendorError::try_from(0xF1) .expect("Valid vendor error code") .into() @@ -579,8 +579,8 @@ impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> { Ok(()) } - inner(self, cred).await.map_err(|e| { - error!("Error updating credential: {e:?}"); + inner(self, cred).await.map_err(|error| { + error!(%error, "Error updating credential."); VendorError::try_from(0xF2) .expect("Valid vendor error code") .into() @@ -644,8 +644,8 @@ impl passkey::authenticator::UserValidationMethod for UserValidationMethodImpl<' } }; - let result = result.map_err(|e| { - error!("Error checking user: {e:?}"); + let result = result.map_err(|error| { + error!(%error, "Error checking user."); Ctap2Error::UserVerificationInvalid })?; diff --git a/crates/bitwarden-fido/src/crypto.rs b/crates/bitwarden-fido/src/crypto.rs index e087b319c..ecfe45034 100644 --- a/crates/bitwarden-fido/src/crypto.rs +++ b/crates/bitwarden-fido/src/crypto.rs @@ -17,14 +17,14 @@ pub enum CoseKeyToPkcs8Error { pub(crate) fn cose_key_to_pkcs8(cose_key: &CoseKey) -> Result, CoseKeyToPkcs8Error> { // cose_key. let secret_key = private_key_from_cose_key(cose_key).map_err(|error| { - log::error!("Failed to extract private key from cose_key: {error:?}"); + tracing::error!(?error, "Failed to extract private key from cose_key."); CoseKeyToPkcs8Error::FailedToExtractPrivateKeyFromCoseKey })?; let vec = secret_key .to_pkcs8_der() .map_err(|error| { - log::error!("Failed to convert P256 private key to PKC8: {error:?}"); + tracing::error!(%error, "Failed to convert P256 private key to PKC8."); CoseKeyToPkcs8Error::FailedToConvertP256PrivateKeyToPkcs8 })? .as_bytes() @@ -39,7 +39,7 @@ pub struct PrivateKeyFromSecretKeyError; pub fn pkcs8_to_cose_key(secret_key: &[u8]) -> Result { let secret_key = SecretKey::from_pkcs8_der(secret_key).map_err(|error| { - log::error!("Failed to extract private key from secret_key: {error:?}"); + tracing::error!(%error, "Failed to extract private key from secret_key."); PrivateKeyFromSecretKeyError })?; diff --git a/crates/bitwarden-ipc/Cargo.toml b/crates/bitwarden-ipc/Cargo.toml index e181292fe..22c96f625 100644 --- a/crates/bitwarden-ipc/Cargo.toml +++ b/crates/bitwarden-ipc/Cargo.toml @@ -25,11 +25,11 @@ bitwarden-error = { workspace = true } bitwarden-threading = { workspace = true } erased-serde = ">=0.4.6, <0.5" js-sys = { workspace = true, optional = true } -log = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } tokio = { features = ["sync", "time", "rt"], workspace = true } +tracing = { workspace = true } tsify = { workspace = true, optional = true } uuid = { workspace = true } wasm-bindgen = { workspace = true, optional = true } diff --git a/crates/bitwarden-ipc/src/ipc_client.rs b/crates/bitwarden-ipc/src/ipc_client.rs index 926b1f325..45b50c93e 100644 --- a/crates/bitwarden-ipc/src/ipc_client.rs +++ b/crates/bitwarden-ipc/src/ipc_client.rs @@ -175,7 +175,7 @@ where let rpc_topic = RPC_REQUEST_PAYLOAD_TYPE_NAME.to_owned(); select! { _ = cancellation_token.cancelled() => { - log::debug!("Cancellation signal received, stopping IPC client"); + tracing::debug!("Cancellation signal received, stopping IPC client"); break; } received = client.crypto.receive(&com_receiver, &client.communication, &client.sessions) => { @@ -185,19 +185,19 @@ where } Ok(message) => { if client_tx.send(message).is_err() { - log::error!("Failed to save incoming message"); + tracing::error!("Failed to save incoming message"); break; }; } - Err(e) => { - log::error!("Error receiving message: {e:?}"); + Err(error) => { + tracing::error!(?error, "Error receiving message"); break; } } } } } - log::debug!("IPC client shutting down"); + tracing::debug!("IPC client shutting down"); client.stop().await; }; @@ -244,7 +244,7 @@ where .await; if result.is_err() { - log::error!("Error sending message: {result:?}"); + tracing::error!(?result, "Error sending message"); self.stop().await; } @@ -378,11 +378,11 @@ where match handle(incoming_message, &client.handlers).await { Ok(outgoing_message) => { if client.send(outgoing_message).await.is_err() { - log::error!("Failed to send response message"); + tracing::error!("Failed to send response message"); } } - Err(e) => { - log::error!("Error handling RPC request: {e:?}"); + Err(error) => { + tracing::error!(%error, "Error handling RPC request"); } } }; diff --git a/crates/bitwarden-threading/Cargo.toml b/crates/bitwarden-threading/Cargo.toml index b322847e3..038b05762 100644 --- a/crates/bitwarden-threading/Cargo.toml +++ b/crates/bitwarden-threading/Cargo.toml @@ -23,11 +23,11 @@ wasm = [ [dependencies] bitwarden-error = { workspace = true } js-sys = { workspace = true, optional = true } -log = { workspace = true } serde = { workspace = true } thiserror = { workspace = true } tokio = { features = ["sync", "time", "rt"], workspace = true } tokio-util = { version = "0.7.15" } +tracing = { workspace = true } wasm-bindgen = { workspace = true, optional = true } [target.'cfg(target_arch="wasm32")'.dependencies] diff --git a/crates/bitwarden-threading/src/thread_bound_runner.rs b/crates/bitwarden-threading/src/thread_bound_runner.rs index 1fcf514ec..1febf615c 100644 --- a/crates/bitwarden-threading/src/thread_bound_runner.rs +++ b/crates/bitwarden-threading/src/thread_bound_runner.rs @@ -138,7 +138,7 @@ where Box::pin(async move { let result = function(state); return_channel_tx.send(result.await).unwrap_or_else(|_| { - log::warn!( + tracing::warn!( "ThreadBoundDispatcher failed to send result back to the caller" ); }); diff --git a/crates/bw/Cargo.toml b/crates/bw/Cargo.toml index d32804670..994bcfd58 100644 --- a/crates/bw/Cargo.toml +++ b/crates/bw/Cargo.toml @@ -29,15 +29,15 @@ bitwarden-vault = { workspace = true } clap = { version = "4.5.4", features = ["derive", "env"] } clap_complete = "4.5.55" color-eyre = "0.6.3" -env_logger = "0.11.1" erased-serde = "0.4.6" inquire = "0.9.1" -log = "0.4.20" serde = { workspace = true } serde_json = { workspace = true } serde_yaml = "0.9.33" thiserror = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread"] } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } [dev-dependencies] bitwarden-crypto = { workspace = true } diff --git a/crates/bw/src/auth/login.rs b/crates/bw/src/auth/login.rs index e07eb7605..8afafc081 100644 --- a/crates/bw/src/auth/login.rs +++ b/crates/bw/src/auth/login.rs @@ -8,7 +8,7 @@ use bitwarden_core::{ }; use color_eyre::eyre::{Result, bail}; use inquire::{Password, Text}; -use log::{debug, error, info}; +use tracing::{debug, error, info}; use crate::vault::{SyncRequest, sync}; @@ -27,10 +27,10 @@ pub(crate) async fn login_password(client: Client, email: Option) -> Res .await?; if let Some(two_factor) = result.two_factor { - error!("{two_factor:?}"); + error!(?two_factor); let two_factor = if let Some(tf) = two_factor.authenticator { - debug!("{tf:?}"); + debug!(?tf); let token = Text::new("Authenticator code").prompt()?; @@ -49,7 +49,7 @@ pub(crate) async fn login_password(client: Client, email: Option) -> Res }) .await?; - info!("Two factor code sent to {tf:?}"); + info!(?tf, "Two factor code sent to"); let token = Text::new("Two factor code").prompt()?; Some(TwoFactorRequest { @@ -70,9 +70,9 @@ pub(crate) async fn login_password(client: Client, email: Option) -> Res }) .await?; - debug!("{result:?}"); + debug!(?result); } else { - debug!("{result:?}"); + debug!(?result); } let res = sync( @@ -82,7 +82,7 @@ pub(crate) async fn login_password(client: Client, email: Option) -> Res }, ) .await?; - info!("{res:#?}"); + info!(?res); Ok(()) } @@ -106,7 +106,7 @@ pub(crate) async fn login_api_key( }) .await?; - debug!("{result:?}"); + debug!(?result); Ok(()) } diff --git a/crates/bw/src/main.rs b/crates/bw/src/main.rs index bc5c201ca..a88fcd39d 100644 --- a/crates/bw/src/main.rs +++ b/crates/bw/src/main.rs @@ -5,7 +5,9 @@ use bitwarden_cli::install_color_eyre; use clap::{CommandFactory, Parser}; use clap_complete::Shell; use color_eyre::eyre::Result; -use env_logger::Target; +use tracing_subscriber::{ + EnvFilter, prelude::__tracing_subscriber_SubscriberExt as _, util::SubscriberInitExt as _, +}; use crate::{command::*, render::CommandResult}; @@ -19,8 +21,24 @@ mod vault; #[tokio::main(flavor = "current_thread")] async fn main() -> Result<()> { - env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")) - .target(Target::Stderr) + // the log level hierarchy is determined by: + // - if RUST_LOG is detected at runtime + // - if RUST_LOG is provided at compile time + // - default to INFO + let filter = EnvFilter::builder() + .with_default_directive( + option_env!("RUST_LOG") + .unwrap_or("info") + .parse() + .expect("should provide valid log level at compile time."), + ) + // parse directives from the RUST_LOG environment variable, + // overriding the default directive for matching targets. + .from_env_lossy(); + + tracing_subscriber::registry() + .with(tracing_subscriber::fmt::layer().with_writer(std::io::stderr)) + .with(filter) .init(); let cli = Cli::parse(); From 788d3d8ffb9b55f24d26a8f5fac6a5308ad9fef8 Mon Sep 17 00:00:00 2001 From: neuronull <9162534+neuronull@users.noreply.github.com> Date: Fri, 21 Nov 2025 15:08:28 -0700 Subject: [PATCH 3/3] empty commit trigger ci