make change_log_ignore a thing

This commit is contained in:
Christien Rioux
2024-03-07 12:38:20 -05:00
parent 6d7c62fb6b
commit 6455aff14a
12 changed files with 280 additions and 4 deletions

View File

@@ -260,6 +260,46 @@ pub fn change_log_level(layer: String, log_level: String) {
}
}
fn apply_ignore_change(ignore_list: Vec<String>, target_change: String) -> Vec<String> {
let mut ignore_list = ignore_list.clone();
for change in target_change.split(',').map(|c| c.trim().to_owned()) {
if change.is_empty() {
continue;
}
if let Some(target) = change.strip_prefix('-') {
ignore_list.retain(|x| x != target);
} else if !ignore_list.contains(&change) {
ignore_list.push(change.to_string());
}
}
ignore_list
}
#[wasm_bindgen()]
pub fn change_log_ignore(layer: String, log_ignore: String) {
let layer = if layer == "all" { "".to_owned() } else { layer };
let filters = (*FILTERS).borrow();
if layer.is_empty() {
// Change all layers
for f in filters.values() {
f.set_ignore_list(Some(apply_ignore_change(
f.ignore_list(),
log_ignore.clone(),
)));
}
} else {
// Change a specific layer
let f = filters.get(layer.as_str()).unwrap();
f.set_ignore_list(Some(apply_ignore_change(
f.ignore_list(),
log_ignore.clone(),
)));
}
}
#[wasm_bindgen()]
pub fn startup_veilid_core(update_callback_js: Function, json_config: String) -> Promise {
let update_callback_js = SendWrapper::new(update_callback_js);

View File

@@ -129,6 +129,44 @@ impl VeilidClient {
}
}
fn apply_ignore_change(ignore_list: Vec<String>, changes: Vec<String>) -> Vec<String> {
let mut ignore_list = ignore_list.clone();
for change in changes.iter().map(|c| c.trim().to_owned()) {
if change.is_empty() {
continue;
}
if let Some(target) = change.strip_prefix('-') {
ignore_list.retain(|x| x != target);
} else if !ignore_list.contains(&change) {
ignore_list.push(change.to_string());
}
}
ignore_list
}
// TODO: can we refine the TS type of `layer`?
pub fn changeLogIgnore(layer: String, changes: Vec<String>) {
let layer = if layer == "all" { "".to_owned() } else { layer };
let filters = (*FILTERS).borrow();
if layer.is_empty() {
// Change all layers
for f in filters.values() {
f.set_ignore_list(Some(Self::apply_ignore_change(
f.ignore_list(),
changes.clone(),
)));
}
} else {
// Change a specific layer
let f = filters.get(layer.as_str()).unwrap();
f.set_ignore_list(Some(Self::apply_ignore_change(
f.ignore_list(),
changes.clone(),
)));
}
}
/// Shut down Veilid and terminate the API.
pub async fn shutdownCore() -> APIResult<()> {
let veilid_api = take_veilid_api()?;

View File

@@ -2,7 +2,6 @@ use super::*;
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
pub use tsify::*;
pub use wasm_bindgen::prelude::*;
macro_rules! from_impl_to_jsvalue {