abstutil/
logger.rs

1use std::sync::Once;
2
3static SETUP: Once = Once::new();
4
5/// ## On native: uses env_log
6///
7/// You can adjust the log level without recompiling with the RUST_LOG env variable.
8///
9/// ```skip
10/// RUST_LOG=debug cargo run --bin game
11/// ```
12///
13/// This can be done on a per lib basis:
14///
15/// ```skip
16/// RUST_LOG=my_lib=debug cargo run --bin game
17/// ```
18///
19/// Or a module-by-module basis:
20///
21/// ```skip
22/// RUST_LOG=my_lib::module=debug cargo run --bin game
23/// ```
24///
25/// You can mix and match:
26///
27/// ```skip
28/// # error logging by default, except the foo:bar module at debug level
29/// # and the entire baz crate at info level
30/// RUST_LOG=error,foo::bar=debug,baz=info cargo run --bin game
31/// ```
32///
33/// For some special cases, you might want to use regex matching by specifying a pattern with the
34/// "/":
35///
36/// ```skip
37/// # only log once every 10k
38/// RUST_LOG="fast_paths=debug/contracted node [0-9]+0000 " mike import_la
39/// ```
40///
41/// ## On web: uses console_log
42///
43/// Can be called multiple times
44pub fn setup() {
45    SETUP.call_once(|| {
46        #[cfg(target_arch = "wasm32")]
47        {
48            console_log::init_with_level(log::Level::Info).unwrap();
49        }
50
51        #[cfg(not(target_arch = "wasm32"))]
52        {
53            use env_logger::{Builder, Env};
54            Builder::from_env(Env::default().default_filter_or("info")).init();
55        }
56    });
57}