log::log_enabled! [-]  [+] [src]

macro_rules! log_enabled {
    ($lvl:expr) => ({
        let lvl = $lvl;
        (lvl != ::log::DEBUG || cfg!(not(ndebug))) &&
        lvl <= ::log::log_level() &&
        ::log::mod_enabled(lvl, module_path!())
    })
}

A macro to test whether a log level is enabled for the current module.

Example

#[macro_use] extern crate log;

struct Point { x: int, y: int }
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