mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-09-11 10:55:27 +03:00
Make logger setup callable twice, to simplify life for callers
This commit is contained in:
parent
2844863c7d
commit
ad99823cc8
@ -1,3 +1,7 @@
|
||||
use std::sync::Once;
|
||||
|
||||
static SETUP: Once = Once::new();
|
||||
|
||||
/// ## On native: uses env_log
|
||||
///
|
||||
/// You can adjust the log level without recompiling with the RUST_LOG env variable.
|
||||
@ -35,15 +39,19 @@
|
||||
/// ```
|
||||
///
|
||||
/// ## On web: uses console_log
|
||||
///
|
||||
/// Can be called multiple times
|
||||
pub fn setup() {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
console_log::init_with_level(log::Level::Info).unwrap();
|
||||
}
|
||||
SETUP.call_once(|| {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
console_log::init_with_level(log::Level::Info).unwrap();
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
use env_logger::{Builder, Env};
|
||||
Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
use env_logger::{Builder, Env};
|
||||
Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user