more test work
This commit is contained in:
@@ -1,20 +1,10 @@
|
||||
// xxx : support for android older than API 24, if we need it someday
|
||||
//mod android_get_if_addrs;
|
||||
//pub use android_get_if_addrs::*;
|
||||
|
||||
mod get_directories;
|
||||
pub use get_directories::*;
|
||||
|
||||
use crate::veilid_config::VeilidConfigLogLevel;
|
||||
use crate::*;
|
||||
use backtrace::Backtrace;
|
||||
use jni::errors::Result as JniResult;
|
||||
use jni::{objects::GlobalRef, objects::JObject, objects::JString, JNIEnv, JavaVM};
|
||||
use jni::{objects::GlobalRef, objects::JObject, JNIEnv, JavaVM};
|
||||
use lazy_static::*;
|
||||
use std::panic;
|
||||
use tracing::*;
|
||||
use tracing_subscriber::prelude::*;
|
||||
use tracing_subscriber::*;
|
||||
|
||||
pub struct AndroidGlobals {
|
||||
pub vm: JavaVM,
|
||||
@@ -32,63 +22,13 @@ lazy_static! {
|
||||
pub static ref ANDROID_GLOBALS: Arc<Mutex<Option<AndroidGlobals>>> = Arc::new(Mutex::new(None));
|
||||
}
|
||||
|
||||
pub fn veilid_core_setup_android_no_log<'a>(env: JNIEnv<'a>, ctx: JObject<'a>) {
|
||||
pub fn veilid_core_setup_android(env: JNIEnv, ctx: JObject) {
|
||||
*ANDROID_GLOBALS.lock() = Some(AndroidGlobals {
|
||||
vm: env.get_java_vm().unwrap(),
|
||||
ctx: env.new_global_ref(ctx).unwrap(),
|
||||
});
|
||||
}
|
||||
|
||||
pub fn veilid_core_setup_android<'a>(
|
||||
env: JNIEnv<'a>,
|
||||
ctx: JObject<'a>,
|
||||
log_tag: &'a str,
|
||||
log_level: VeilidConfigLogLevel,
|
||||
) {
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "tracing")] {
|
||||
// Set up subscriber and layers
|
||||
let subscriber = Registry::default();
|
||||
let mut layers = Vec::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());
|
||||
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() {
|
||||
error!(
|
||||
"panic occurred in file '{}' at line {}",
|
||||
location.file(),
|
||||
location.line(),
|
||||
);
|
||||
} else {
|
||||
error!("panic occurred but can't get location information...");
|
||||
}
|
||||
if let Some(s) = panic_info.payload().downcast_ref::<&str>() {
|
||||
error!("panic payload: {:?}", s);
|
||||
} else if let Some(s) = panic_info.payload().downcast_ref::<String>() {
|
||||
error!("panic payload: {:?}", s);
|
||||
} else if let Some(a) = panic_info.payload().downcast_ref::<std::fmt::Arguments>() {
|
||||
error!("panic payload: {:?}", a);
|
||||
} else {
|
||||
error!("no panic payload");
|
||||
}
|
||||
error!("Backtrace:\n{:?}", bt);
|
||||
}));
|
||||
|
||||
veilid_core_setup_android_no_log(env, ctx);
|
||||
}
|
||||
|
||||
pub fn get_android_globals() -> (JavaVM, GlobalRef) {
|
||||
let globals_locked = ANDROID_GLOBALS.lock();
|
||||
let globals = globals_locked.as_ref().unwrap();
|
||||
|
@@ -1,87 +0,0 @@
|
||||
use backtrace::Backtrace;
|
||||
use log::*;
|
||||
use simplelog::*;
|
||||
use std::fs::OpenOptions;
|
||||
use std::panic;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn veilid_core_setup<'a>(
|
||||
log_tag: &'a str,
|
||||
terminal_log: Option<Level>,
|
||||
file_log: Option<(Level, &Path)>,
|
||||
) {
|
||||
if let Err(e) = veilid_core_setup_internal(log_tag, terminal_log, file_log) {
|
||||
panic!("failed to set up veilid-core: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn veilid_core_setup_internal<'a>(
|
||||
_log_tag: &'a str,
|
||||
terminal_log: Option<Level>,
|
||||
file_log: Option<(Level, &Path)>,
|
||||
) -> Result<(), String> {
|
||||
let mut logs: Vec<Box<dyn SharedLogger>> = Vec::new();
|
||||
|
||||
let mut cb = ConfigBuilder::new();
|
||||
for ig in veilid_core::DEFAULT_LOG_IGNORE_LIST {
|
||||
cb.add_filter_ignore_str(ig);
|
||||
}
|
||||
|
||||
if let Some(level) = terminal_log {
|
||||
logs.push(TermLogger::new(
|
||||
level.to_level_filter(),
|
||||
cb.build(),
|
||||
TerminalMode::Mixed,
|
||||
ColorChoice::Auto,
|
||||
))
|
||||
}
|
||||
if let Some((level, log_path)) = file_log {
|
||||
let logfile = OpenOptions::new()
|
||||
.truncate(true)
|
||||
.create(true)
|
||||
.write(true)
|
||||
.open(log_path)
|
||||
.map_err(|e| {
|
||||
format!(
|
||||
"log open error: {} path={:?} all_dirs={:?}",
|
||||
e,
|
||||
log_path,
|
||||
std::fs::read_dir(std::env::var("HOME").unwrap())
|
||||
.unwrap()
|
||||
.map(|d| d.unwrap().path())
|
||||
.collect::<Vec<PathBuf>>()
|
||||
)
|
||||
})?;
|
||||
logs.push(WriteLogger::new(
|
||||
level.to_level_filter(),
|
||||
cb.build(),
|
||||
logfile,
|
||||
))
|
||||
}
|
||||
CombinedLogger::init(logs).map_err(|e| format!("logger init error: {}", e))?;
|
||||
|
||||
panic::set_hook(Box::new(|panic_info| {
|
||||
let bt = Backtrace::new();
|
||||
if let Some(location) = panic_info.location() {
|
||||
error!(
|
||||
"panic occurred in file '{}' at line {}",
|
||||
location.file(),
|
||||
location.line(),
|
||||
);
|
||||
} else {
|
||||
error!("panic occurred but can't get location information...");
|
||||
}
|
||||
if let Some(s) = panic_info.payload().downcast_ref::<&str>() {
|
||||
error!("panic payload: {:?}", s);
|
||||
} else if let Some(s) = panic_info.payload().downcast_ref::<String>() {
|
||||
error!("panic payload: {:?}", s);
|
||||
} else if let Some(a) = panic_info.payload().downcast_ref::<std::fmt::Arguments>() {
|
||||
error!("panic payload: {:?}", a);
|
||||
} else {
|
||||
error!("no panic payload");
|
||||
}
|
||||
error!("Backtrace:\n{:?}", bt);
|
||||
}));
|
||||
|
||||
Ok(())
|
||||
}
|
@@ -10,6 +10,4 @@ pub use table_store::*;
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
pub mod android;
|
||||
#[cfg(all(target_os = "ios", feature = "veilid_core_ios_tests"))]
|
||||
pub mod ios_test_setup;
|
||||
pub mod network_interfaces;
|
||||
|
Reference in New Issue
Block a user