log::log_enabled!
[−]
[src]
macro_rules! log_enabled { ($lvl:expr) => { ... }; }
Unstable (
rustc_private
): use the crates.io log
library instead
A macro to test whether a log level is enabled for the current module.
Examples
#![feature(rustc_private)] #[macro_use] extern crate log; struct Point { x: i32, y: i32 } fn some_expensive_computation() -> Point { Point { x: 1, y: 2 } } fn main() { if log_enabled!(log::DEBUG) { let x = some_expensive_computation(); debug!("x.x = {}, x.y = {}", x.x, x.y); } }#[macro_use] extern crate log; struct Point { x: i32, y: i32 } fn some_expensive_computation() -> Point { Point { x: 1, y: 2 } } fn main() { if log_enabled!(log::DEBUG) { let x = some_expensive_computation(); debug!("x.x = {}, x.y = {}", x.x, x.y); } }
Assumes the binary is main
:
$ RUST_LOG=error ./main
$ RUST_LOG=debug ./main
DEBUG:main: x.x = 1, x.y = 2