diff --git a/Cargo.lock b/Cargo.lock index 1b911d90..6a59c1ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4228,6 +4228,7 @@ dependencies = [ "rustls", "rustls-pemfile", "secrecy", + "send_wrapper", "serde 1.0.136", "serde-big-array", "serde_cbor", @@ -4327,7 +4328,6 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "wasm-bindgen-test", - "wasm-logger", "wee_alloc", ] diff --git a/veilid-core/Cargo.toml b/veilid-core/Cargo.toml index 17e3a2df..940b310b 100644 --- a/veilid-core/Cargo.toml +++ b/veilid-core/Cargo.toml @@ -88,6 +88,7 @@ getrandom = { version = "^0", features = ["js"] } ws_stream_wasm = "^0" async_executors = { version = "^0", default-features = false, features = [ "bindgen" ]} async-lock = "^2" +send_wrapper = "^0" # Configuration for WASM32 'web-sys' crate [target.'cfg(target_arch = "wasm32")'.dependencies.web-sys] diff --git a/veilid-core/src/api_logger.rs b/veilid-core/src/api_logger.rs index 1597fa76..d2fe2e59 100644 --- a/veilid-core/src/api_logger.rs +++ b/veilid-core/src/api_logger.rs @@ -4,10 +4,22 @@ use crate::xx::*; use log::{set_boxed_logger, set_max_level, Level, LevelFilter, Log, Metadata, Record}; use once_cell::sync::OnceCell; -struct ApiLoggerInner { - level: LevelFilter, - filter_ignore: Cow<'static, [Cow<'static, str>]>, - update_callback: UpdateCallback, +cfg_if! { + if #[cfg(target_arch = "wasm32")] { + use send_wrapper::*; + + struct ApiLoggerInner { + level: LevelFilter, + filter_ignore: Cow<'static, [Cow<'static, str>]>, + update_callback: SendWrapper, + } + } else { + struct ApiLoggerInner { + level: LevelFilter, + filter_ignore: Cow<'static, [Cow<'static, str>]>, + update_callback: UpdateCallback, + } + } } #[derive(Clone)] @@ -19,10 +31,20 @@ static API_LOGGER: OnceCell = OnceCell::new(); impl ApiLogger { fn new_inner(level: LevelFilter, update_callback: UpdateCallback) -> ApiLoggerInner { - ApiLoggerInner { - level, - filter_ignore: Default::default(), - update_callback, + cfg_if! { + if #[cfg(target_arch = "wasm32")] { + ApiLoggerInner { + level, + filter_ignore: Default::default(), + update_callback: SendWrapper::new(update_callback), + } + } else { + ApiLoggerInner { + level, + filter_ignore: Default::default(), + update_callback, + } + } } } diff --git a/veilid-core/src/core_context.rs b/veilid-core/src/core_context.rs index 52f30cd7..a7ecafae 100644 --- a/veilid-core/src/core_context.rs +++ b/veilid-core/src/core_context.rs @@ -1,3 +1,4 @@ +use crate::api_logger::*; use crate::attachment_manager::*; use crate::dht::crypto::Crypto; use crate::intf::*; @@ -9,7 +10,6 @@ cfg_if! { if #[cfg(target_arch = "wasm32")] { pub type UpdateCallback = Arc; } else { - use crate::api_logger::*; pub type UpdateCallback = Arc; } @@ -62,21 +62,11 @@ impl ServicesContext { pub async fn startup(&mut self) -> Result<(), VeilidAPIError> { let log_level: VeilidConfigLogLevel = self.config.get().log_level; if log_level != VeilidConfigLogLevel::Off { - cfg_if! { - if #[cfg(target_arch = "wasm32")] { - // Logging is managed by application - } else { - ApiLogger::init( - log_level.to_level_filter(), - self.update_callback.clone(), - ) - .await; - for ig in crate::DEFAULT_LOG_IGNORE_LIST { - ApiLogger::add_filter_ignore_str(ig); - } - info!("Veilid logging initialized"); - } + ApiLogger::init(log_level.to_level_filter(), self.update_callback.clone()).await; + for ig in crate::DEFAULT_LOG_IGNORE_LIST { + ApiLogger::add_filter_ignore_str(ig); } + info!("Veilid logging initialized"); } info!("Veilid API starting up"); @@ -171,13 +161,7 @@ impl ServicesContext { info!("Veilid API shutdown complete"); // api logger terminate is idempotent - cfg_if! { - if #[cfg(target_arch = "wasm32")] { - // Logging is managed by application - } else { - ApiLogger::terminate().await; - } - } + ApiLogger::terminate().await; // send final shutdown update (self.update_callback)(VeilidUpdate::Shutdown); diff --git a/veilid-core/src/lib.rs b/veilid-core/src/lib.rs index 7d61dbb4..fc00509b 100644 --- a/veilid-core/src/lib.rs +++ b/veilid-core/src/lib.rs @@ -4,9 +4,7 @@ #[macro_use] extern crate alloc; -#[cfg(not(target_arch = "wasm32"))] mod api_logger; - mod attachment_manager; mod callback_state_machine; mod connection_manager; diff --git a/veilid-wasm/Cargo.toml b/veilid-wasm/Cargo.toml index 18e934a2..e79b5487 100644 --- a/veilid-wasm/Cargo.toml +++ b/veilid-wasm/Cargo.toml @@ -12,7 +12,6 @@ crate-type = ["cdylib", "rlib"] wasm-bindgen = { version = "^0", features = ["serde-serialize"] } console_error_panic_hook = "^0" wee_alloc = "^0" -wasm-logger = "^0" log = "^0" veilid-core = { path = "../veilid-core" } cfg-if = "^1" diff --git a/veilid-wasm/src/lib.rs b/veilid-wasm/src/lib.rs index b296448d..a3b7c98b 100644 --- a/veilid-wasm/src/lib.rs +++ b/veilid-wasm/src/lib.rs @@ -103,7 +103,6 @@ where #[wasm_bindgen(js_namespace = veilid)] pub fn initialize_veilid_wasm() { console_error_panic_hook::set_once(); - wasm_logger::init(wasm_logger::Config::new(Level::Info)); } #[wasm_bindgen(js_namespace = veilid)]