diff --git a/Cargo.lock b/Cargo.lock index c935083aa3..31dbc9343a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -481,7 +481,6 @@ dependencies = [ "env_logger 0.10.0", "futures", "lazy_static", - "libvcx_logger", "log", "messages", "num-bigint", @@ -3216,17 +3215,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "libvcx_logger" -version = "0.62.0" -dependencies = [ - "android_logger", - "aries_vcx_core", - "chrono", - "env_logger 0.10.0", - "log", -] - [[package]] name = "libvdrtools" version = "0.8.6" @@ -5203,8 +5191,8 @@ dependencies = [ "async-trait", "chrono", "did_parser", + "env_logger 0.10.0", "lazy_static", - "libvcx_logger", "log", "public_key", "rand 0.8.5", diff --git a/Cargo.toml b/Cargo.toml index 133ece0f45..8945cfacda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ members = [ "aries/misc/indy_ledger_response_parser", "aries/misc/wallet_migrator", "aries/misc/test_utils", - "aries/misc/legacy/libvcx_logger", "did_core/did_doc", "did_core/did_methods/did_peer", "did_core/did_methods/did_key", diff --git a/aries/aries_vcx/Cargo.toml b/aries/aries_vcx/Cargo.toml index 6a1228a607..3241a99309 100644 --- a/aries/aries_vcx/Cargo.toml +++ b/aries/aries_vcx/Cargo.toml @@ -78,7 +78,6 @@ backtrace = { optional = true, version = "0.3" } [dev-dependencies] test_utils = { path = "../misc/test_utils" } -libvcx_logger = { path = "../misc/legacy/libvcx_logger" } wallet_migrator = { path = "../misc/wallet_migrator" } async-channel = "1.7.1" tokio = { version = "1.20", features = ["rt", "macros", "rt-multi-thread"] } diff --git a/aries/aries_vcx/tests/test_mysql_wallet.rs b/aries/aries_vcx/tests/test_mysql_wallet.rs index b0b24c02b1..c36d9f0373 100644 --- a/aries/aries_vcx/tests/test_mysql_wallet.rs +++ b/aries/aries_vcx/tests/test_mysql_wallet.rs @@ -10,12 +10,10 @@ mod dbtests { base_wallet::{did_wallet::DidWallet, BaseWallet, ManageWallet}, indy::indy_wallet_config::IndyWalletConfig, }; - use libvcx_logger::LibvcxDefaultLogger; #[tokio::test] #[ignore] async fn test_mysql_init_issuer_with_mysql_wallet() -> Result<(), Box> { - LibvcxDefaultLogger::init_testing_logger(); let db_name = format!("mysqltest_{}", uuid::Uuid::new_v4()).replace('-', "_"); let storage_config = json!({ "read_host": "localhost", diff --git a/aries/misc/legacy/libvcx_logger/Cargo.toml b/aries/misc/legacy/libvcx_logger/Cargo.toml deleted file mode 100644 index ca1962fa02..0000000000 --- a/aries/misc/legacy/libvcx_logger/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "libvcx_logger" -version.workspace = true -authors.workspace = true -description.workspace = true -license.workspace = true -edition.workspace = true - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aries_vcx_core = { path = "../../../aries_vcx_core" } -chrono = "0.4" -env_logger = "0.10" -log = "0.4" - -[target.'cfg(target_os = "android")'.dependencies] -android_logger = "0.13.3" diff --git a/aries/misc/legacy/libvcx_logger/src/lib.rs b/aries/misc/legacy/libvcx_logger/src/lib.rs deleted file mode 100644 index 63ff30059d..0000000000 --- a/aries/misc/legacy/libvcx_logger/src/lib.rs +++ /dev/null @@ -1,105 +0,0 @@ -use std::{env, io::Write, sync::Once}; - -#[cfg(target_os = "android")] -use android_logger::Config; -use aries_vcx_core::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult}; -use chrono::{ - format::{DelayedFormat, StrftimeItems}, - Local, -}; -use env_logger::{fmt::Formatter, Builder as EnvLoggerBuilder}; -use log::{info, LevelFilter, Record}; - -static TEST_LOGGING_INIT: Once = Once::new(); - -pub fn init_test_logging() { - TEST_LOGGING_INIT.call_once(|| { - LibvcxDefaultLogger::init_testing_logger(); - }) -} - -pub struct LibvcxDefaultLogger; - -fn _get_timestamp<'a>() -> DelayedFormat> { - Local::now().format("%Y-%m-%d %H:%M:%S.%f") -} - -fn text_format(buf: &mut Formatter, record: &Record) -> std::io::Result<()> { - let level = buf.default_styled_level(record.level()); - writeln!( - buf, - "{}|{:>5}|{:<30}|{:>35}:{:<4}| {}", - _get_timestamp(), - level, - record.target(), - record.file().get_or_insert(""), - record.line().get_or_insert(0), - record.args() - ) -} - -fn text_no_color_format(buf: &mut Formatter, record: &Record) -> std::io::Result<()> { - let level = record.level(); - writeln!( - buf, - "{}|{:>5}|{:<30}|{:>35}:{:<4}| {}", - _get_timestamp(), - level, - record.target(), - record.file().get_or_insert(""), - record.line().get_or_insert(0), - record.args() - ) -} - -impl LibvcxDefaultLogger { - pub fn init_testing_logger() { - if let Ok(log_pattern) = env::var("RUST_LOG") { - LibvcxDefaultLogger::init(Some(log_pattern)) - .expect("Failed to initialize LibvcxDefaultLogger for testing") - } - } - - pub fn init(pattern: Option) -> VcxCoreResult<()> { - let pattern = pattern.or(env::var("RUST_LOG").ok()); - if cfg!(target_os = "android") { - #[cfg(target_os = "android")] - let log_filter = match pattern.as_ref() { - Some(val) => match val.to_lowercase().as_ref() { - "error" => Config::default().with_max_level(log::LevelFilter::Error), - "warn" => Config::default().with_max_level(log::LevelFilter::Warn), - "info" => Config::default().with_max_level(log::LevelFilter::Info), - "debug" => Config::default().with_max_level(log::LevelFilter::Debug), - "trace" => Config::default().with_max_level(log::LevelFilter::Trace), - _ => Config::default().with_max_level(log::LevelFilter::Error), - }, - None => Config::default().with_max_level(log::LevelFilter::Error), - }; - - //Set logging to off when deploying production android app. - #[cfg(target_os = "android")] - android_logger::init_once(log_filter); - info!("Logging for Android"); - } else { - let formatter = match env::var("RUST_LOG_FORMATTER") { - Ok(val) => match val.as_str() { - "text_no_color" => text_no_color_format, - _ => text_format, - }, - _ => text_format, - }; - EnvLoggerBuilder::new() - .format(formatter) - .filter(None, LevelFilter::Off) - .parse_filters(pattern.as_deref().unwrap_or("warn")) - .try_init() - .map_err(|err| { - AriesVcxCoreError::from_msg( - AriesVcxCoreErrorKind::LoggingError, - format!("Cannot init logger: {:?}", err), - ) - })?; - } - Ok(()) - } -} diff --git a/aries/misc/test_utils/Cargo.toml b/aries/misc/test_utils/Cargo.toml index b1604ead2d..87d05da471 100644 --- a/aries/misc/test_utils/Cargo.toml +++ b/aries/misc/test_utils/Cargo.toml @@ -17,13 +17,13 @@ anoncreds = ["aries_vcx_core/anoncreds"] [dependencies] anoncreds_types = { path = "../../misc/anoncreds_types" } aries_vcx_core = { path = "../../aries_vcx_core" } -libvcx_logger = { path = "../legacy/libvcx_logger" } did_parser = { path = "../../../did_core/did_parser" } public_key = { path = "../../../did_core/public_key" } lazy_static = "1" serde_json = "1" -log = "0.4" -chrono = "0.4" rand = "0.8" uuid = { version = "1", default-features = false, features = ["v4"] } async-trait = "0.1" +chrono = "0.4" +env_logger = "0.10" +log = "0.4" diff --git a/aries/misc/test_utils/src/devsetup.rs b/aries/misc/test_utils/src/devsetup.rs index 6c0dc91092..019426b223 100644 --- a/aries/misc/test_utils/src/devsetup.rs +++ b/aries/misc/test_utils/src/devsetup.rs @@ -22,7 +22,6 @@ use aries_vcx_core::{ }; use chrono::{DateTime, Duration, Utc}; use did_parser::Did; -use libvcx_logger::init_test_logging; use log::{debug, info}; use crate::constants::{POOL1_TXN, TRUSTEE_SEED}; @@ -32,6 +31,7 @@ pub mod vdr_proxy_ledger; #[cfg(feature = "vdr_proxy_ledger")] use crate::devsetup::vdr_proxy_ledger::dev_build_profile_vdr_proxy_ledger; +use crate::logger::init_logger; #[cfg(feature = "vdrtools_wallet")] pub mod vdrtools_wallet; @@ -131,7 +131,7 @@ pub struct SetupPoolDirectory { impl SetupMocks { pub fn init() -> SetupMocks { - init_test_logging(); + init_logger(); SetupMocks } } @@ -216,7 +216,7 @@ pub async fn build_setup_profile() -> SetupProfile< impl BaseAnonCreds, impl BaseWallet, > { - init_test_logging(); + init_logger(); let genesis_file_path = get_temp_file_path(POOL1_TXN).to_str().unwrap().to_string(); create_testpool_genesis_txn_file(&genesis_file_path); @@ -249,7 +249,7 @@ pub async fn build_setup_profile() -> SetupProfile< impl SetupPoolDirectory { pub async fn init() -> SetupPoolDirectory { debug!("SetupPoolDirectory init >> going to setup agency environment"); - init_test_logging(); + init_logger(); let genesis_file_path = get_temp_file_path(POOL1_TXN).to_str().unwrap().to_string(); create_testpool_genesis_txn_file(&genesis_file_path); diff --git a/aries/misc/test_utils/src/lib.rs b/aries/misc/test_utils/src/lib.rs index 85c68c796e..b058415ceb 100644 --- a/aries/misc/test_utils/src/lib.rs +++ b/aries/misc/test_utils/src/lib.rs @@ -3,4 +3,5 @@ pub mod mockdata; pub mod random; #[rustfmt::skip] pub mod constants; +pub mod logger; pub mod mock_wallet; diff --git a/aries/misc/test_utils/src/logger.rs b/aries/misc/test_utils/src/logger.rs new file mode 100644 index 0000000000..40e8f2e9f4 --- /dev/null +++ b/aries/misc/test_utils/src/logger.rs @@ -0,0 +1,83 @@ +use std::{env, io::Write, sync::Once}; + +use aries_vcx_core::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult}; +use chrono::{ + format::{DelayedFormat, StrftimeItems}, + Local, +}; +use env_logger::{fmt::Formatter, Builder as EnvLoggerBuilder}; +use log::{LevelFilter, Record}; + +static TEST_LOGGING_INIT: Once = Once::new(); + +pub fn init_logger() { + TEST_LOGGING_INIT.call_once(|| { + LibvcxDefaultLogger::init_testing_logger(); + }) +} + +pub struct LibvcxDefaultLogger; + +fn _get_timestamp<'a>() -> DelayedFormat> { + Local::now().format("%Y-%m-%d %H:%M:%S.%f") +} + +fn text_format(buf: &mut Formatter, record: &Record) -> std::io::Result<()> { + let level = buf.default_styled_level(record.level()); + writeln!( + buf, + "{}|{:>5}|{:<30}|{:>35}:{:<4}| {}", + _get_timestamp(), + level, + record.target(), + record.file().get_or_insert(""), + record.line().get_or_insert(0), + record.args() + ) +} + +fn text_no_color_format(buf: &mut Formatter, record: &Record) -> std::io::Result<()> { + let level = record.level(); + writeln!( + buf, + "{}|{:>5}|{:<30}|{:>35}:{:<4}| {}", + _get_timestamp(), + level, + record.target(), + record.file().get_or_insert(""), + record.line().get_or_insert(0), + record.args() + ) +} + +impl LibvcxDefaultLogger { + pub fn init_testing_logger() { + if let Ok(log_pattern) = env::var("RUST_LOG") { + LibvcxDefaultLogger::init(Some(log_pattern)) + .expect("Failed to initialize LibvcxDefaultLogger for testing") + } + } + + pub fn init(pattern: Option) -> VcxCoreResult<()> { + let pattern = pattern.or(env::var("RUST_LOG").ok()); + let formatter = match env::var("RUST_LOG_FORMATTER") { + Ok(val) => match val.as_str() { + "text_no_color" => text_no_color_format, + _ => text_format, + }, + _ => text_format, + }; + EnvLoggerBuilder::new() + .format(formatter) + .filter(None, LevelFilter::Off) + .parse_filters(pattern.as_deref().unwrap_or("warn")) + .try_init() + .map_err(|err| { + AriesVcxCoreError::from_msg( + AriesVcxCoreErrorKind::LoggingError, + format!("Cannot init logger: {:?}", err), + ) + })?; + Ok(()) + } +}