Skip to content

Commit

Permalink
Cleanup logging dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas committed Nov 12, 2023
1 parent baf941f commit c23054b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 48 deletions.
1 change: 0 additions & 1 deletion aries_vcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ backtrace = { optional = true, version = "0.3" }

[dev-dependencies]
test_utils = { path = "../tools/test_utils" }
libvcx_logger = { path = "../tools/libvcx_logger" }
wallet_migrator = { path = "../wallet_migrator" }
async-channel = "1.7.1"
tokio = { version = "1.20", features = ["rt", "macros", "rt-multi-thread"] }
2 changes: 0 additions & 2 deletions aries_vcx/tests/test_mysql_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ mod dbtests {
IndySdkWallet, WalletConfig, WalletConfigBuilder,
},
};
use libvcx_logger::LibvcxDefaultLogger;

#[tokio::test]
#[ignore]
async fn test_mysql_init_issuer_with_mysql_wallet() -> Result<(), Box<dyn Error>> {
LibvcxDefaultLogger::init_testing_logger();
let db_name = format!("mysqltest_{}", uuid::Uuid::new_v4()).replace('-', "_");
let storage_config = json!({
"read_host": "localhost",
Expand Down
3 changes: 0 additions & 3 deletions tools/libvcx_logger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ 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"
63 changes: 21 additions & 42 deletions tools/libvcx_logger/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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};
use env_logger::{Builder as EnvLoggerBuilder, fmt::Formatter};
use log::{LevelFilter, Record};

use aries_vcx_core::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult};

static TEST_LOGGING_INIT: Once = Once::new();

Expand Down Expand Up @@ -62,44 +61,24 @@ impl LibvcxDefaultLogger {

pub fn init(pattern: Option<String>) -> 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,
},
let formatter = match env::var("RUST_LOG_FORMATTER") {
Ok(val) => match val.as_str() {
"text_no_color" => text_no_color_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),
)
})?;
}
},
_ => 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(())
}
}

0 comments on commit c23054b

Please sign in to comment.