From b631dab17f475dc15cab7de1ef996b8ef27e7729 Mon Sep 17 00:00:00 2001 From: vms Date: Wed, 9 Dec 2020 11:34:39 +0300 Subject: [PATCH] reexport WASM_LOG_ENV_NAME --- Cargo.toml | 2 +- crates/main/src/lib.rs | 2 ++ crates/main/src/logger.rs | 19 ++++++++++--------- src/lib.rs | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1cb0b72..5c64236 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fluence" -version = "0.2.9" # remember to update html_root_url +version = "0.2.10" # remember to update html_root_url description = "Fluence backend SDK for developing backend applications for the Fluence network" documentation = "https://docs.rs/fluence/" repository = "https://github.com/fluencelabs/rust-sdk" diff --git a/crates/main/src/lib.rs b/crates/main/src/lib.rs index 18cfeee..83ebdaf 100644 --- a/crates/main/src/lib.rs +++ b/crates/main/src/lib.rs @@ -48,6 +48,8 @@ pub use export_allocator::deallocate; pub use logger::WasmLoggerBuilder; #[cfg(feature = "logger")] pub use logger::TargetMap; +#[cfg(feature = "logger")] +pub use logger::WASM_LOG_ENV_NAME; pub use result::get_result_ptr; pub use result::get_result_size; diff --git a/crates/main/src/logger.rs b/crates/main/src/logger.rs index ab85a81..2d1925c 100644 --- a/crates/main/src/logger.rs +++ b/crates/main/src/logger.rs @@ -44,6 +44,12 @@ use log::Level as LogLevel; +/// By default, logger will be initialized with log level from this environment variable. +pub const WASM_LOG_ENV_NAME: &'static str = "WASM_LOG"; + +/// If WASM_LOG_ENV isn't set, then this level will be used as the default. +const WASM_DEFAULT_LOG_LEVEL: LogLevel = LogLevel::Info; + pub type TargetMap = std::collections::HashMap<&'static str, i64>; /// The Wasm Logger. @@ -75,15 +81,10 @@ impl WasmLoggerBuilder { pub fn new() -> Self { use std::str::FromStr; - const WASM_LOG_ENV_NAME: &'static str = "WASM_LOG"; - const RUST_DEFAULT_LOG_LEVEL: LogLevel = LogLevel::Info; - - let log_level = match std::env::var(WASM_LOG_ENV_NAME) { - Ok(log_level_str) => { - LogLevel::from_str(&log_level_str).unwrap_or(RUST_DEFAULT_LOG_LEVEL) - } - Err(_) => RUST_DEFAULT_LOG_LEVEL, - }; + let log_level = std::env::var(WASM_LOG_ENV_NAME) + .map_or(WASM_DEFAULT_LOG_LEVEL, |log_level_str| { + LogLevel::from_str(&log_level_str).unwrap_or(WASM_DEFAULT_LOG_LEVEL) + }); Self { log_level, diff --git a/src/lib.rs b/src/lib.rs index cbd11a6..630174d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,7 +55,7 @@ //! pub fn curl_get(url: String) -> String; //! } //! ``` -#![doc(html_root_url = "https://docs.rs/fluence/0.2.9")] +#![doc(html_root_url = "https://docs.rs/fluence/0.2.10")] #![deny( dead_code, nonstandard_style,