Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: cleanup logging dependencies #1060

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
58 changes: 18 additions & 40 deletions tools/libvcx_logger/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
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 log::{LevelFilter, Record};

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

Expand Down Expand Up @@ -62,44 +60,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(())
}
}
Loading