diff --git a/Cargo.lock b/Cargo.lock index 641a5d46..b5d76904 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4736,6 +4736,17 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-android" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12612be8f868a09c0ceae7113ff26afe79d81a24473a393cb9120ece162e86c0" +dependencies = [ + "android_log-sys", + "tracing", + "tracing-subscriber", +] + [[package]] name = "tracing-appender" version = "0.2.2" @@ -5102,7 +5113,6 @@ dependencies = [ name = "veilid-core" version = "0.1.0" dependencies = [ - "android_logger 0.11.0", "async-io", "async-lock", "async-std", @@ -5177,6 +5187,7 @@ dependencies = [ "tokio-stream", "tokio-util 0.7.3", "tracing", + "tracing-android", "tracing-error", "tracing-subscriber", "tracing-wasm", diff --git a/veilid-core/Cargo.toml b/veilid-core/Cargo.toml index d9016ba0..7ec5379e 100644 --- a/veilid-core/Cargo.toml +++ b/veilid-core/Cargo.toml @@ -133,7 +133,7 @@ jni = "^0" jni-sys = "^0" ndk = { version = "^0", features = ["trace"] } ndk-glue = { version = "^0", features = ["logger"] } -android_logger = { version = "^0" } +tracing-android = { version = "^0" } backtrace = { version = "^0" } # Dependenices for all Unix (Linux, Android, MacOS, iOS) diff --git a/veilid-core/src/core_context.rs b/veilid-core/src/core_context.rs index f1d34442..9897f68e 100644 --- a/veilid-core/src/core_context.rs +++ b/veilid-core/src/core_context.rs @@ -195,7 +195,7 @@ impl VeilidCoreContext { ) -> Result { cfg_if! { if #[cfg(target_os = "android")] { - if utils::android::ANDROID_GLOBALS.lock().is_none() { + if crate::intf::utils::android::ANDROID_GLOBALS.lock().is_none() { error!("Android globals are not set up"); return Err(VeilidAPIError::Internal { message: "Android globals are not set up".to_owned() }); } diff --git a/veilid-core/src/intf/native/utils/android/mod.rs b/veilid-core/src/intf/native/utils/android/mod.rs index cfb86f0d..d7bdd15b 100644 --- a/veilid-core/src/intf/native/utils/android/mod.rs +++ b/veilid-core/src/intf/native/utils/android/mod.rs @@ -5,14 +5,17 @@ mod get_directories; pub use get_directories::*; +use crate::veilid_config::VeilidConfigLogLevel; use crate::xx::*; -use android_logger::{Config, FilterBuilder}; +use crate::*; use backtrace::Backtrace; use jni::errors::Result as JniResult; use jni::{objects::GlobalRef, objects::JObject, objects::JString, JNIEnv, JavaVM}; use lazy_static::*; -use log::*; use std::panic; +use tracing::*; +use tracing_subscriber::prelude::*; +use tracing_subscriber::*; pub struct AndroidGlobals { pub vm: JavaVM, @@ -41,19 +44,25 @@ pub fn veilid_core_setup_android<'a>( env: JNIEnv<'a>, ctx: JObject<'a>, log_tag: &'a str, - log_level: Level, + log_level: VeilidConfigLogLevel, ) { - android_logger::init_once( - Config::default() - .with_min_level(log_level) - .with_tag(log_tag) - .with_filter( - FilterBuilder::new() - .filter(Some(log_tag), log_level.to_level_filter()) - .build(), - ), - ); + // Set up subscriber and layers + let subscriber = Registry::default(); + let mut layers = Vec::new(); + let mut filters = BTreeMap::new(); + let filter = VeilidLayerFilter::new(log_level, None); + let layer = tracing_android::layer(log_tag) + .expect("failed to set up android logging") + .with_filter(filter.clone()); + filters.insert("system", filter); + layers.push(layer.boxed()); + let subscriber = subscriber.with(layers); + subscriber + .try_init() + .expect("failed to init android tracing"); + + // Set up panic hook for backtraces panic::set_hook(Box::new(|panic_info| { let bt = Backtrace::new(); if let Some(location) = panic_info.location() { diff --git a/veilid-core/src/network_manager/native/network_class_discovery.rs b/veilid-core/src/network_manager/native/network_class_discovery.rs index d3f3dcff..5d7ae6a7 100644 --- a/veilid-core/src/network_manager/native/network_class_discovery.rs +++ b/veilid-core/src/network_manager/native/network_class_discovery.rs @@ -3,7 +3,6 @@ use super::*; use futures_util::stream::FuturesUnordered; use futures_util::FutureExt; use stop_token::future::FutureExt as StopTokenFutureExt; -use tokio::task::spawn_blocking; struct DetectedPublicDialInfo { dial_info: DialInfo, diff --git a/veilid-core/src/tests/android/app/build.gradle b/veilid-core/src/tests/android/app/build.gradle index f12a7cda..cd66b082 100644 --- a/veilid-core/src/tests/android/app/build.gradle +++ b/veilid-core/src/tests/android/app/build.gradle @@ -68,7 +68,7 @@ cargo { prebuiltToolchains = true profile = gradle.startParameter.taskNames.any{it.toLowerCase().contains("debug")} ? "debug" : "release" features { - defaultAnd("android_tests") + defaultAnd("android_tests", "rt-tokio") } } diff --git a/veilid-core/src/tests/native/mod.rs b/veilid-core/src/tests/native/mod.rs index f5e161bd..e5ea0e2a 100644 --- a/veilid-core/src/tests/native/mod.rs +++ b/veilid-core/src/tests/native/mod.rs @@ -19,7 +19,12 @@ pub extern "system" fn Java_com_veilid_veilidcore_veilidcore_1android_1tests_Mai _class: JClass, ctx: JObject, ) { - crate::intf::utils::android::veilid_core_setup_android(env, ctx, "veilid_core", Level::Trace); + crate::intf::utils::android::veilid_core_setup_android( + env, + ctx, + "veilid_core", + crate::veilid_config::VeilidConfigLogLevel::Trace, + ); run_all_tests(); }