nandi/rustnimpublic Fork 0
main
Commits
Clone
git clone https://git.rickub.com/nandi/rustnim.git
git clone ssh://git@rickub.com/nandi/rustnim.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

035-log.rs · 28 lines · 1.6 KBRust Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//@ extern: log
// `log`'s value to its 61 dependents in libcosmic's tree is 20
// `macro_rules!`, so the macros are lowered directly against the facade's
// documented behaviour, as `bitflags!` is. The oracle links the real crate;
// rustnim does not get it and has to reproduce it.
//
// The behaviour worth pinning: with no logger installed every macro is a
// no-op and `log_enabled!` stays false even after `set_max_level`, because
// the facade consults the logger as well as the level. `Display` for a
// level is upper-case where `Debug` is not.
use log::{debug, error, info, log, log_enabled, trace, warn, Level, LevelFilter};
fn main() {
    println!("default max_level {:?}", log::max_level());
    println!("enabled {} {}", log_enabled!(Level::Error), log_enabled!(Level::Trace));
    // With no logger installed these emit nothing at all.
    error!("e"); warn!("w"); info!("i {}", 1); debug!("d"); trace!("t");
    log!(Level::Info, "explicit {}", 2);

    log::set_max_level(LevelFilter::Info);
    println!("after set  {:?}", log::max_level());
    println!("enabled {} {} {}", log_enabled!(Level::Error), log_enabled!(Level::Info), log_enabled!(Level::Debug));
    info!("still nothing, no logger");

    println!("levels {} {} {} {} {}", Level::Error as usize, Level::Warn as usize, Level::Info as usize, Level::Debug as usize, Level::Trace as usize);
    println!("filters {} {}", LevelFilter::Off as usize, LevelFilter::Trace as usize);
    println!("ord {} {}", Level::Error < Level::Warn, Level::Trace > Level::Info);
    println!("disp {} {:?}", Level::Warn, Level::Warn);
}