nandi/rustnimpublic Fork 0
7db79919131ab55e23a1730bf78c360e05d9977e
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
Lower the `log` facade, and add explicit enum discriminants 12c0a01 nandithebull 17h ago1//@ extern: log
2// `log`'s value to its 61 dependents in libcosmic's tree is 20
3// `macro_rules!`, so the macros are lowered directly against the facade's
4// documented behaviour, as `bitflags!` is. The oracle links the real crate;
5// rustnim does not get it and has to reproduce it.
6//
7// The behaviour worth pinning: with no logger installed every macro is a
8// no-op and `log_enabled!` stays false even after `set_max_level`, because
9// the facade consults the logger as well as the level. `Display` for a
10// level is upper-case where `Debug` is not.
11use log::{debug, error, info, log, log_enabled, trace, warn, Level, LevelFilter};
12fn main() {
13 println!("default max_level {:?}", log::max_level());
14 println!("enabled {} {}", log_enabled!(Level::Error), log_enabled!(Level::Trace));
15 // With no logger installed these emit nothing at all.
16 error!("e"); warn!("w"); info!("i {}", 1); debug!("d"); trace!("t");
17 log!(Level::Info, "explicit {}", 2);
18
19 log::set_max_level(LevelFilter::Info);
20 println!("after set {:?}", log::max_level());
21 println!("enabled {} {} {}", log_enabled!(Level::Error), log_enabled!(Level::Info), log_enabled!(Level::Debug));
22 info!("still nothing, no logger");
23
24 println!("levels {} {} {} {} {}", Level::Error as usize, Level::Warn as usize, Level::Info as usize, Level::Debug as usize, Level::Trace as usize);
25 println!("filters {} {}", LevelFilter::Off as usize, LevelFilter::Trace as usize);
26 println!("ord {} {}", Level::Error < Level::Warn, Level::Trace > Level::Info);
27 println!("disp {} {:?}", Level::Warn, Level::Warn);
28}