re-enable wasm api logger
This commit is contained in:
parent
ca85b555aa
commit
243c53606e
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -4228,6 +4228,7 @@ dependencies = [
|
|||||||
"rustls",
|
"rustls",
|
||||||
"rustls-pemfile",
|
"rustls-pemfile",
|
||||||
"secrecy",
|
"secrecy",
|
||||||
|
"send_wrapper",
|
||||||
"serde 1.0.136",
|
"serde 1.0.136",
|
||||||
"serde-big-array",
|
"serde-big-array",
|
||||||
"serde_cbor",
|
"serde_cbor",
|
||||||
@ -4327,7 +4328,6 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-futures",
|
"wasm-bindgen-futures",
|
||||||
"wasm-bindgen-test",
|
"wasm-bindgen-test",
|
||||||
"wasm-logger",
|
|
||||||
"wee_alloc",
|
"wee_alloc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -88,6 +88,7 @@ getrandom = { version = "^0", features = ["js"] }
|
|||||||
ws_stream_wasm = "^0"
|
ws_stream_wasm = "^0"
|
||||||
async_executors = { version = "^0", default-features = false, features = [ "bindgen" ]}
|
async_executors = { version = "^0", default-features = false, features = [ "bindgen" ]}
|
||||||
async-lock = "^2"
|
async-lock = "^2"
|
||||||
|
send_wrapper = "^0"
|
||||||
|
|
||||||
# Configuration for WASM32 'web-sys' crate
|
# Configuration for WASM32 'web-sys' crate
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
|
[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
|
||||||
|
@ -4,10 +4,22 @@ use crate::xx::*;
|
|||||||
use log::{set_boxed_logger, set_max_level, Level, LevelFilter, Log, Metadata, Record};
|
use log::{set_boxed_logger, set_max_level, Level, LevelFilter, Log, Metadata, Record};
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
|
|
||||||
struct ApiLoggerInner {
|
cfg_if! {
|
||||||
level: LevelFilter,
|
if #[cfg(target_arch = "wasm32")] {
|
||||||
filter_ignore: Cow<'static, [Cow<'static, str>]>,
|
use send_wrapper::*;
|
||||||
update_callback: UpdateCallback,
|
|
||||||
|
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)]
|
#[derive(Clone)]
|
||||||
@ -19,10 +31,20 @@ static API_LOGGER: OnceCell<ApiLogger> = OnceCell::new();
|
|||||||
|
|
||||||
impl ApiLogger {
|
impl ApiLogger {
|
||||||
fn new_inner(level: LevelFilter, update_callback: UpdateCallback) -> ApiLoggerInner {
|
fn new_inner(level: LevelFilter, update_callback: UpdateCallback) -> ApiLoggerInner {
|
||||||
ApiLoggerInner {
|
cfg_if! {
|
||||||
level,
|
if #[cfg(target_arch = "wasm32")] {
|
||||||
filter_ignore: Default::default(),
|
ApiLoggerInner {
|
||||||
update_callback,
|
level,
|
||||||
|
filter_ignore: Default::default(),
|
||||||
|
update_callback: SendWrapper::new(update_callback),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ApiLoggerInner {
|
||||||
|
level,
|
||||||
|
filter_ignore: Default::default(),
|
||||||
|
update_callback,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use crate::api_logger::*;
|
||||||
use crate::attachment_manager::*;
|
use crate::attachment_manager::*;
|
||||||
use crate::dht::crypto::Crypto;
|
use crate::dht::crypto::Crypto;
|
||||||
use crate::intf::*;
|
use crate::intf::*;
|
||||||
@ -9,7 +10,6 @@ cfg_if! {
|
|||||||
if #[cfg(target_arch = "wasm32")] {
|
if #[cfg(target_arch = "wasm32")] {
|
||||||
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate)>;
|
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate)>;
|
||||||
} else {
|
} else {
|
||||||
use crate::api_logger::*;
|
|
||||||
|
|
||||||
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate) + Send + Sync>;
|
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate) + Send + Sync>;
|
||||||
}
|
}
|
||||||
@ -62,21 +62,11 @@ impl ServicesContext {
|
|||||||
pub async fn startup(&mut self) -> Result<(), VeilidAPIError> {
|
pub async fn startup(&mut self) -> Result<(), VeilidAPIError> {
|
||||||
let log_level: VeilidConfigLogLevel = self.config.get().log_level;
|
let log_level: VeilidConfigLogLevel = self.config.get().log_level;
|
||||||
if log_level != VeilidConfigLogLevel::Off {
|
if log_level != VeilidConfigLogLevel::Off {
|
||||||
cfg_if! {
|
ApiLogger::init(log_level.to_level_filter(), self.update_callback.clone()).await;
|
||||||
if #[cfg(target_arch = "wasm32")] {
|
for ig in crate::DEFAULT_LOG_IGNORE_LIST {
|
||||||
// Logging is managed by application
|
ApiLogger::add_filter_ignore_str(ig);
|
||||||
} 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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
info!("Veilid logging initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Veilid API starting up");
|
info!("Veilid API starting up");
|
||||||
@ -171,13 +161,7 @@ impl ServicesContext {
|
|||||||
info!("Veilid API shutdown complete");
|
info!("Veilid API shutdown complete");
|
||||||
|
|
||||||
// api logger terminate is idempotent
|
// api logger terminate is idempotent
|
||||||
cfg_if! {
|
ApiLogger::terminate().await;
|
||||||
if #[cfg(target_arch = "wasm32")] {
|
|
||||||
// Logging is managed by application
|
|
||||||
} else {
|
|
||||||
ApiLogger::terminate().await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// send final shutdown update
|
// send final shutdown update
|
||||||
(self.update_callback)(VeilidUpdate::Shutdown);
|
(self.update_callback)(VeilidUpdate::Shutdown);
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
mod api_logger;
|
mod api_logger;
|
||||||
|
|
||||||
mod attachment_manager;
|
mod attachment_manager;
|
||||||
mod callback_state_machine;
|
mod callback_state_machine;
|
||||||
mod connection_manager;
|
mod connection_manager;
|
||||||
|
@ -12,7 +12,6 @@ crate-type = ["cdylib", "rlib"]
|
|||||||
wasm-bindgen = { version = "^0", features = ["serde-serialize"] }
|
wasm-bindgen = { version = "^0", features = ["serde-serialize"] }
|
||||||
console_error_panic_hook = "^0"
|
console_error_panic_hook = "^0"
|
||||||
wee_alloc = "^0"
|
wee_alloc = "^0"
|
||||||
wasm-logger = "^0"
|
|
||||||
log = "^0"
|
log = "^0"
|
||||||
veilid-core = { path = "../veilid-core" }
|
veilid-core = { path = "../veilid-core" }
|
||||||
cfg-if = "^1"
|
cfg-if = "^1"
|
||||||
|
@ -103,7 +103,6 @@ where
|
|||||||
#[wasm_bindgen(js_namespace = veilid)]
|
#[wasm_bindgen(js_namespace = veilid)]
|
||||||
pub fn initialize_veilid_wasm() {
|
pub fn initialize_veilid_wasm() {
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
wasm_logger::init(wasm_logger::Config::new(Level::Info));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen(js_namespace = veilid)]
|
#[wasm_bindgen(js_namespace = veilid)]
|
||||||
|
Loading…
Reference in New Issue
Block a user