utils.rs
1 use cfg_if::cfg_if; 2 use log::Level; 3 4 cfg_if! { 5 // When the `console_error_panic_hook` feature is enabled, we can call the 6 // `set_panic_hook` function at least once during initialization, and then 7 // we will get better error messages if our code ever panics. 8 // 9 // For more details see 10 // https://github.com/rustwasm/console_error_panic_hook#readme 11 if #[cfg(feature = "console_error_panic_hook")] { 12 extern crate console_error_panic_hook; 13 pub use self::console_error_panic_hook::set_once as set_panic_hook; 14 } else { 15 #[inline] 16 pub fn set_panic_hook() {} 17 } 18 } 19 20 cfg_if! { 21 // When the `console_log` feature is enabled, forward log calls to the 22 // JS console. 23 if #[cfg(feature = "console_log")] { 24 pub fn init_log(level: Level) { 25 // Best effort, ignore error if initialization fails. 26 // (This could be the case if the logger is initialized multiple 27 // times.) 28 let _ = console_log::init_with_level(level); 29 } 30 } else { 31 pub fn init_log(_level: Level) {} 32 } 33 }