re-enable wasm api logger

This commit is contained in:
John Smith 2022-03-15 09:51:45 -04:00
parent ca85b555aa
commit 243c53606e
7 changed files with 38 additions and 35 deletions

2
Cargo.lock generated
View File

@ -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",
]

View File

@ -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]

View File

@ -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<UpdateCallback>,
}
} 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<ApiLogger> = 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,
}
}
}
}

View File

@ -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<dyn Fn(VeilidUpdate)>;
} else {
use crate::api_logger::*;
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate) + Send + Sync>;
}
@ -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);

View File

@ -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;

View File

@ -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"

View File

@ -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)]