[][src]Macro log::log_enabled

macro_rules! log_enabled {
    (target: $target:expr, $lvl:expr) => { ... };
    ($lvl:expr) => { ... };
}

Determines if a message logged at the specified level in that module will be logged.

This can be used to avoid expensive computation of log message arguments if the message would be ignored anyway.

Examples

use log::Level::Debug;
use log::{debug, log_enabled};

# fn foo() {
if log_enabled!(Debug) {
    let data = expensive_call();
    debug!("expensive debug data: {} {}", data.x, data.y);
}
if log_enabled!(target: "Global", Debug) {
   let data = expensive_call();
   debug!(target: "Global", "expensive debug data: {} {}", data.x, data.y);
}
# }
# struct Data { x: u32, y: u32 }
# fn expensive_call() -> Data { Data { x: 0, y: 0 } }
# fn main() {}