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

Do not include logger implementation in aries-vcx #1149

Merged
merged 1 commit into from
Mar 15, 2024
Merged
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
14 changes: 1 addition & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion aries/aries_vcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
2 changes: 0 additions & 2 deletions aries/aries_vcx/tests/test_mysql_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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
18 changes: 0 additions & 18 deletions aries/misc/legacy/libvcx_logger/Cargo.toml

This file was deleted.

105 changes: 0 additions & 105 deletions aries/misc/legacy/libvcx_logger/src/lib.rs

This file was deleted.

6 changes: 3 additions & 3 deletions aries/misc/test_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 4 additions & 4 deletions aries/misc/test_utils/src/devsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -131,7 +131,7 @@ pub struct SetupPoolDirectory {

impl SetupMocks {
pub fn init() -> SetupMocks {
init_test_logging();
init_logger();
SetupMocks
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions aries/misc/test_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pub mod mockdata;
pub mod random;
#[rustfmt::skip]
pub mod constants;
pub mod logger;
pub mod mock_wallet;
83 changes: 83 additions & 0 deletions aries/misc/test_utils/src/logger.rs
Original file line number Diff line number Diff line change
@@ -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<StrftimeItems<'a>> {
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<String>) -> 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(())
}
}
Loading