WASM work
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use crate::api_logger::*;
|
||||
use crate::attachment_manager::*;
|
||||
use crate::dht::crypto::Crypto;
|
||||
use crate::intf::*;
|
||||
@@ -10,6 +9,8 @@ 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>;
|
||||
}
|
||||
}
|
||||
@@ -59,18 +60,23 @@ impl ServicesContext {
|
||||
}
|
||||
|
||||
pub async fn startup(&mut self) -> Result<(), VeilidAPIError> {
|
||||
let api_log_level: VeilidConfigLogLevel = self.config.get().api_log_level;
|
||||
if api_log_level != VeilidConfigLogLevel::Off {
|
||||
ApiLogger::init(
|
||||
api_log_level.to_level_filter(),
|
||||
self.update_callback.clone(),
|
||||
)
|
||||
.await;
|
||||
for ig in crate::DEFAULT_LOG_IGNORE_LIST {
|
||||
ApiLogger::add_filter_ignore_str(ig);
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
info!("Veilid API logging initialized");
|
||||
}
|
||||
|
||||
info!("Veilid API starting up");
|
||||
@@ -165,7 +171,13 @@ impl ServicesContext {
|
||||
info!("Veilid API shutdown complete");
|
||||
|
||||
// api logger terminate is idempotent
|
||||
ApiLogger::terminate().await;
|
||||
cfg_if! {
|
||||
if #[cfg(target_arch = "wasm32")] {
|
||||
// Logging is managed by application
|
||||
} else {
|
||||
ApiLogger::terminate().await;
|
||||
}
|
||||
}
|
||||
|
||||
// send final shutdown update
|
||||
(self.update_callback)(VeilidUpdate::Shutdown);
|
||||
|
@@ -4,16 +4,6 @@ use crate::xx::*;
|
||||
use core::sync::atomic::{AtomicI8, Ordering};
|
||||
use js_sys::{global, Reflect};
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "wee_alloc")] {
|
||||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
||||
// allocator.
|
||||
extern crate wee_alloc;
|
||||
#[global_allocator]
|
||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
// Use `js_namespace` here to bind `console.log(..)` instead of just
|
||||
|
@@ -4,7 +4,9 @@
|
||||
#[macro_use]
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod api_logger;
|
||||
|
||||
mod attachment_manager;
|
||||
mod callback_state_machine;
|
||||
mod connection_manager;
|
||||
|
@@ -169,7 +169,7 @@ fn config_callback(key: String) -> ConfigCallbackReturn {
|
||||
match key.as_str() {
|
||||
"program_name" => Ok(Box::new(String::from("Veilid"))),
|
||||
"namespace" => Ok(Box::new(String::from(""))),
|
||||
"api_log_level" => Ok(Box::new(VeilidConfigLogLevel::Off)),
|
||||
"log_level" => Ok(Box::new(VeilidConfigLogLevel::Off)),
|
||||
"capabilities.protocol_udp" => Ok(Box::new(true)),
|
||||
"capabilities.protocol_connect_tcp" => Ok(Box::new(true)),
|
||||
"capabilities.protocol_accept_tcp" => Ok(Box::new(true)),
|
||||
@@ -270,7 +270,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.api_log_level, VeilidConfigLogLevel::Off);
|
||||
assert_eq!(inner.log_level, VeilidConfigLogLevel::Off);
|
||||
assert_eq!(inner.capabilities.protocol_udp, true);
|
||||
assert_eq!(inner.capabilities.protocol_connect_tcp, true);
|
||||
assert_eq!(inner.capabilities.protocol_accept_tcp, true);
|
||||
|
@@ -21,7 +21,6 @@ pub use network_manager::NetworkManager;
|
||||
pub use routing_table::RoutingTable;
|
||||
pub use rpc_processor::InfoAnswer;
|
||||
|
||||
use api_logger::*;
|
||||
use core::fmt;
|
||||
use core_context::{api_shutdown, VeilidCoreContext};
|
||||
use rpc_processor::{RPCError, RPCProcessor};
|
||||
@@ -1219,8 +1218,15 @@ impl VeilidAPI {
|
||||
}
|
||||
|
||||
// Change api logging level if it is enabled
|
||||
pub async fn change_api_log_level(&self, log_level: VeilidConfigLogLevel) {
|
||||
ApiLogger::change_log_level(log_level.to_level_filter());
|
||||
pub async fn change_log_level(&self, log_level: VeilidConfigLogLevel) {
|
||||
cfg_if! {
|
||||
if #[cfg(target_arch = "wasm32")] {
|
||||
set_max_level(log_level.to_level_filter());
|
||||
} else {
|
||||
use api_logger::ApiLogger;
|
||||
ApiLogger::change_log_level(log_level.to_level_filter());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
@@ -206,7 +206,7 @@ impl Default for VeilidConfigLogLevel {
|
||||
pub struct VeilidConfigInner {
|
||||
pub program_name: String,
|
||||
pub namespace: String,
|
||||
pub api_log_level: VeilidConfigLogLevel,
|
||||
pub log_level: VeilidConfigLogLevel,
|
||||
pub capabilities: VeilidConfigCapabilities,
|
||||
pub protected_store: VeilidConfigProtectedStore,
|
||||
pub table_store: VeilidConfigTableStore,
|
||||
@@ -262,7 +262,7 @@ impl VeilidConfig {
|
||||
let mut inner = self.inner.write();
|
||||
get_config!(inner.program_name);
|
||||
get_config!(inner.namespace);
|
||||
get_config!(inner.api_log_level);
|
||||
get_config!(inner.log_level);
|
||||
get_config!(inner.capabilities.protocol_udp);
|
||||
get_config!(inner.capabilities.protocol_connect_tcp);
|
||||
get_config!(inner.capabilities.protocol_accept_tcp);
|
||||
|
Reference in New Issue
Block a user