Skip to content

Commit

Permalink
Separated logger into its own crate
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Mircea <[email protected]>
  • Loading branch information
bobozaur committed Oct 23, 2023
1 parent be0bf6b commit df339f3
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 38 deletions.
35 changes: 23 additions & 12 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ members = [
"indy_ledger_response_parser",
"wallet_migrator",
"tools/simple_message_relay",
"tools/test_utils"
"tools/test_utils",
"tools/libvcx_logger"
]

[workspace.package]
Expand Down
4 changes: 1 addition & 3 deletions aries_vcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ tokio = { version = "1.20.4" }
thiserror = "1.0.37"
url = { version = "2.3", features = ["serde"] }

[target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.13.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: 1 addition & 1 deletion aries_vcx/tests/test_mysql_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod dbtests {
IndySdkWallet, WalletConfig, WalletConfigBuilder,
},
};
use test_utils::test_logger::LibvcxDefaultLogger;
use libvcx_logger::LibvcxDefaultLogger;

#[tokio::test]
#[ignore]
Expand Down
2 changes: 1 addition & 1 deletion libvcx_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ uuid = { version = "1.4.1", default-features = false, features = ["v4"] }
agency_client = { path = "../agency_client" }
async-trait = "0.1.61"
url = "2.3.1"
test_utils = {path = "../tools/test_utils" }
wallet_migrator = { path = "../wallet_migrator" }

[dev-dependencies]
test_utils = {path = "../tools/test_utils" }
tokio = { version = "1.20", features = [ "rt", "macros" ] }
1 change: 1 addition & 0 deletions libvcx_core/src/api_vcx/api_global/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ pub async fn wallet_migrate(wallet_config: &WalletConfig) -> LibvcxResult<()> {
migration_res.map_err(|e| LibvcxError::from_msg(LibvcxErrorKind::WalletMigrationFailed, e))
}

#[cfg(test)]
pub mod test_utils {
use ::test_utils::devsetup::TempFile;
use aries_vcx::{
Expand Down
11 changes: 8 additions & 3 deletions libvcx_core/src/api_vcx/api_handle/credential.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(test)]
use aries_vcx::agency_client::testing::mocking::AgencyMockDecrypted;
use aries_vcx::{
agency_client::testing::mocking::AgencyMockDecrypted,
handlers::issuance::{holder::Holder, mediated_holder::holder_find_message_to_handle},
messages::{
msg_fields::protocols::cred_issuance::{
Expand All @@ -10,6 +11,7 @@ use aries_vcx::{
},
};
use serde_json;
#[cfg(test)]
use test_utils::{
constants::GET_MESSAGES_DECRYPTED_RESPONSE, mockdata::mockdata_credex::ARIES_CREDENTIAL_OFFER,
};
Expand Down Expand Up @@ -316,8 +318,11 @@ pub async fn get_credential_offer_messages_with_conn_handle(
connection_handle
);

AgencyMockDecrypted::set_next_decrypted_response(GET_MESSAGES_DECRYPTED_RESPONSE);
AgencyMockDecrypted::set_next_decrypted_message(ARIES_CREDENTIAL_OFFER);
#[cfg(test)]
{
AgencyMockDecrypted::set_next_decrypted_response(GET_MESSAGES_DECRYPTED_RESPONSE);
AgencyMockDecrypted::set_next_decrypted_message(ARIES_CREDENTIAL_OFFER);
}

let credential_offers: Vec<AriesMessage> = mediated_connection::get_messages(connection_handle)
.await?
Expand Down
18 changes: 18 additions & 0 deletions tools/libvcx_logger/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[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"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{env, io::Write};
use std::{env, io::Write, sync::Once};

#[cfg(target_os = "android")]
use android_logger::Filter;
Expand All @@ -10,6 +10,14 @@ use chrono::{
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<StrftimeItems<'a>> {
Expand Down
2 changes: 1 addition & 1 deletion tools/test_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ credx = ["aries_vcx_core/credx"]
[dependencies]
aries_vcx_core = { path = "../../aries_vcx_core" }
agency_client = { path = "../../agency_client" }
libvcx_logger = { path = "../libvcx_logger" }
lazy_static = "1"
serde_json = "1"
env_logger = "0.10"
log = "0.4"
chrono = "0.4"
rand = "0.8"
Expand Down
12 changes: 1 addition & 11 deletions tools/test_utils/src/devsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,16 @@ use aries_vcx_core::{
};
use chrono::{DateTime, Duration, Utc};
use lazy_static::lazy_static;
use libvcx_logger::init_test_logging;
use log::{debug, info, warn};

use crate::{
constants::{POOL1_TXN, TRUSTEE_SEED},
mockdata::{mock_anoncreds::MockAnoncreds, mock_ledger::MockLedger},
test_logger::LibvcxDefaultLogger,
};

const DEFAULT_AML_LABEL: &str = "eula";

lazy_static! {
static ref TEST_LOGGING_INIT: Once = Once::new();
}

pub fn init_test_logging() {
TEST_LOGGING_INIT.call_once(|| {
LibvcxDefaultLogger::init_testing_logger();
})
}

pub fn write_file<P: AsRef<Path>>(file: P, content: &str) -> VcxCoreResult<()>
where
P: std::convert::AsRef<std::ffi::OsStr>,
Expand Down
1 change: 0 additions & 1 deletion tools/test_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod devsetup;
pub mod mockdata;
pub mod random;
pub mod test_logger;
#[rustfmt::skip]
pub mod constants;
4 changes: 2 additions & 2 deletions wrappers/vcx-napi-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ wallet_migrator = { path = "../../wallet_migrator" }
log = "0.4.16"
napi = { version = "2.10.14", default-features = false, features = [ "async" ] }
napi-derive = { version = "2.10.1" }
uuid = { version = "0.8", default-features = false, features = ["v4"] }
uuid = { version = "1.5.0", default-features = false, features = ["v4"] }
chrono = "0.4.23"
test_utils = { path = "../../tools/test_utils" }
libvcx_logger = { path = "../../tools/libvcx_logger" }

[build-dependencies]
napi-build = "2.0.1"
2 changes: 1 addition & 1 deletion wrappers/vcx-napi-rs/src/api/logging.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use libvcx_core::errors::error::LibvcxError;
use libvcx_logger::LibvcxDefaultLogger;
use napi_derive::napi;
use test_utils::test_logger::LibvcxDefaultLogger;

use crate::error::to_napi_err;

Expand Down

0 comments on commit df339f3

Please sign in to comment.