diff --git a/Cargo.lock b/Cargo.lock index 07cbc86f..f26b1e92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,6 +28,21 @@ dependencies = [ "stream-cipher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "android_log-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "android_logger" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "android_log-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "arrayvec" version = "0.4.7" @@ -307,6 +322,14 @@ dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "log-panics" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "lru-cache" version = "0.1.1" @@ -582,7 +605,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "zcash-wallet-sdk-poc" version = "0.0.1" dependencies = [ + "android_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "jni 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log-panics 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf-codegen-pure 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -644,6 +670,8 @@ dependencies = [ "checksum aes 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e6fb1737cdc8da3db76e90ca817a194249a38fcb500c2e6ecec39b29448aa873" "checksum aes-soft 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "67cc03b0a090a05cb01e96998a01905d7ceedce1bc23b756c0bb7faa0682ccb1" "checksum aesni 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6810b7fb9f2bb4f76f05ac1c170b8dde285b6308955dc3afd89710268c958d9e" +"checksum android_log-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b8052e2d8aabbb8d556d6abbcce2a22b9590996c5f849b9c7ce4544a2e3b984e" +"checksum android_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bad99185bc195e796e1591740c26716667b58ac9210a48731f71f803fc6ca43a" "checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" "checksum ascii 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a5fc969a8ce2c9c0c4b0429bb8431544f6658283c8326ba5ff8c762b75369335" "checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a" @@ -682,6 +710,7 @@ dependencies = [ "checksum libsqlite3-sys 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "742b695cbfb89e549dca6960a55e6802f67d352e33e97859ee46dee835211b0f" "checksum linked-hash-map 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7860ec297f7008ff7a1e3382d7f7e1dcd69efc94751a2284bafc3d013c2aa939" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" +"checksum log-panics 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae0136257df209261daa18d6c16394757c63e032e27aafd8b07788b051082bef" "checksum lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4d06ff7ff06f729ce5f4e227876cb88d10bc59cd4ae1e09fbb2bde15c850dc21" "checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" diff --git a/Cargo.toml b/Cargo.toml index 6d476182..f1343793 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ publish = false protobuf = "2" rand = "0.4" rusqlite = { version = "0.15", features = ["bundled"] } +log = "0.4" [dependencies.zcash_client_backend] git = "https://github.com/str4d/librustzcash.git" @@ -20,6 +21,8 @@ rev = "63ec78bb857a258a97d25a5a6e747389996e566a" [target.'cfg(target_os="android")'.dependencies] jni = { version = "0.10", default-features = false } +android_logger = "0.6" +log-panics = "2.0.0" [build-dependencies] protobuf-codegen-pure = "2" diff --git a/src/main/rust/lib.rs b/src/main/rust/lib.rs index 2e79bd45..deb50e73 100644 --- a/src/main/rust/lib.rs +++ b/src/main/rust/lib.rs @@ -1,3 +1,6 @@ +#[macro_use] +extern crate log; + extern crate protobuf; extern crate rusqlite; extern crate zcash_client_backend; @@ -75,16 +78,35 @@ fn scan_cached_blocks( #[cfg(target_os = "android")] #[allow(non_snake_case)] pub mod android { + extern crate android_logger; extern crate jni; + extern crate log_panics; + use log::Level; use protobuf::Message; + use self::android_logger::Filter; use self::jni::objects::{JClass, JString}; use self::jni::sys::{jbyteArray, jint, jobjectArray, jsize, jstring}; use self::jni::JNIEnv; use super::{address_from_extfvk, extfvk_from_seed, scan_cached_blocks}; + #[no_mangle] + pub unsafe extern "C" fn Java_cash_z_wallet_sdk_jni_JniConverter_initLogs( + _env: JNIEnv, + _: JClass, + ) { + android_logger::init_once( + Filter::default().with_min_level(Level::Trace), + Some("cash.z.rust.logs"), + ); + + log_panics::init(); + + debug!("logs have been initialized successfully"); + } + #[no_mangle] pub unsafe extern "C" fn Java_cash_z_wallet_sdk_jni_JniConverter_getAddress( env: JNIEnv,