Set minimal log level during initialization (#114)

This commit is contained in:
Mike Voronov 2021-06-04 17:07:46 +03:00 committed by GitHub
parent 93f71908e0
commit 49f3afda4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 7 deletions

View File

@ -16,11 +16,19 @@
use air::log_targets::TARGET_MAP;
pub fn init_logger() {
use log::LevelFilter;
pub fn init_logger(default_level: Option<LevelFilter>) {
let target_map = TARGET_MAP.iter().cloned().collect();
fluence::WasmLoggerBuilder::new()
let builder = fluence::WasmLoggerBuilder::new()
.with_target_map(target_map)
.filter("jsonpath_lib", log::LevelFilter::Info)
.build()
.unwrap();
.filter("jsonpath_lib", log::LevelFilter::Info);
let builder = if let Some(default_level) = default_level {
builder.with_log_level(default_level)
} else {
builder
};
builder.build().unwrap();
}

View File

@ -34,7 +34,7 @@ use air::InterpreterOutcome;
use fluence::marine;
pub fn main() {
logger::init_logger();
logger::init_logger(None);
}
#[marine]

View File

@ -38,7 +38,14 @@ pub const DEFAULT_LOG_LEVEL: LevelFilter = LevelFilter::Trace;
#[wasm_bindgen(start)]
pub fn main() {
logger::init_logger();
// it's necessary to initialize it with the minimal allowed log level,
// because otherwise it's impossible to set less level than used during initialization.
const MINIMAL_LOG_LEVEL: LevelFilter = LevelFilter::Trace;
logger::init_logger(Some(MINIMAL_LOG_LEVEL));
// this one is just a guard for possible changes of the invoke function where some log-prone
// code could added before the setting max log level from a function parameter.
log::set_max_level(LevelFilter::Info);
}
#[wasm_bindgen]