move toward api logging

This commit is contained in:
John Smith
2022-01-31 10:11:18 -05:00
parent cc328d30fa
commit 29b5ec5334
11 changed files with 454 additions and 473 deletions

View File

@@ -23,22 +23,7 @@ lazy_static! {
pub static ref ANDROID_GLOBALS: Arc<Mutex<Option<AndroidGlobals>>> = Arc::new(Mutex::new(None));
}
pub fn veilid_core_setup_android<'a>(
env: JNIEnv<'a>,
ctx: JObject<'a>,
log_tag: &'a str,
log_level: Level,
) {
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(),
),
);
pub fn veilid_core_setup_android_no_log<'a>(env: JNIEnv<'a>, ctx: JObject<'a>) {
panic::set_hook(Box::new(|panic_info| {
let bt = Backtrace::new();
if let Some(location) = panic_info.location() {
@@ -68,6 +53,26 @@ pub fn veilid_core_setup_android<'a>(
});
}
pub fn veilid_core_setup_android<'a>(
env: JNIEnv<'a>,
ctx: JObject<'a>,
log_tag: &'a str,
log_level: Level,
) {
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(),
),
);
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();

View File

@@ -175,6 +175,7 @@ pub fn config_callback(key: String) -> ConfigCallbackReturn {
match key.as_str() {
"program_name" => Ok(Box::new(String::from("Veilid"))),
"namespace" => Ok(Box::new(String::from(""))),
"log_to_api" => Ok(Box::new(false)),
"capabilities.protocol_udp" => Ok(Box::new(true)),
"capabilities.protocol_connect_tcp" => Ok(Box::new(true)),
"capabilities.protocol_accept_tcp" => Ok(Box::new(true)),
@@ -275,6 +276,7 @@ pub async fn test_config() {
let inner = vc.get();
assert_eq!(inner.program_name, String::from("Veilid"));
assert_eq!(inner.namespace, String::from(""));
assert_eq!(inner.log_to_api, false);
assert_eq!(inner.capabilities.protocol_udp, true);
assert_eq!(inner.capabilities.protocol_connect_tcp, true);
assert_eq!(inner.capabilities.protocol_accept_tcp, true);

View File

@@ -106,12 +106,34 @@ macro_rules! parse_error {
/////////////////////////////////////////////////////////////////////////////////////////////////////
#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub enum VeilidLogLevel {
Error = 1,
Warn,
Info,
Debug,
Trace,
}
impl VeilidLogLevel {
pub fn from_log_level(level: log::Level) -> VeilidLogLevel {
match level {
Level::Error => VeilidLogLevel::Error,
Level::Warn => VeilidLogLevel::Warn,
Level::Info => VeilidLogLevel::Info,
Level::Debug => VeilidLogLevel::Debug,
Level::Trace => VeilidLogLevel::Trace,
}
}
}
#[derive(Debug, Clone)]
pub enum VeilidUpdate {
Log(VeilidLogLevel, String),
Attachment(AttachmentState),
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct VeilidState {
pub attachment: AttachmentState,
}
@@ -1144,6 +1166,9 @@ impl VeilidAPI {
timeout_ms: Option<u32>,
) -> Result<(), VeilidAPIError> {
match update {
VeilidUpdate::Log(_l, _s) => {
// No point in waiting for a log
}
VeilidUpdate::Attachment(cs) => {
self.attachment_manager()?
.wait_for_state(cs, timeout_ms)

View File

@@ -176,6 +176,7 @@ pub struct VeilidConfigCapabilities {
pub struct VeilidConfigInner {
pub program_name: String,
pub namespace: String,
pub log_to_api: bool,
pub capabilities: VeilidConfigCapabilities,
pub protected_store: VeilidConfigProtectedStore,
pub table_store: VeilidConfigTableStore,
@@ -220,6 +221,7 @@ impl VeilidConfig {
let mut inner = self.inner.write();
get_config!(inner.program_name);
get_config!(inner.namespace);
get_config!(inner.log_to_api);
get_config!(inner.capabilities.protocol_udp);
get_config!(inner.capabilities.protocol_connect_tcp);
get_config!(inner.capabilities.protocol_accept_tcp);