summaryrefslogtreecommitdiff
path: root/rust-src/bch_bindgen/src/log.rs
blob: 32927f162b36db20bbe9b7e18ce3df0deb0557d5 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::sync::atomic::{AtomicU8, Ordering};

pub const MUTE: u8 = 0;
pub const ERROR: u8 = 1;
pub const INFO: u8 = 2;
pub const DEBUG: u8 = 3;

// error level by default
pub static VERBOSE: AtomicU8 = AtomicU8::new(ERROR);

#[inline]
pub fn set_verbose_level(level: u8) {
    VERBOSE.store(level, Ordering::SeqCst);
}

pub fn max_level() -> u8 {
    VERBOSE.load(Ordering::SeqCst)
}

#[macro_export]
macro_rules! info {
    ($($arg:tt)*) => {
        if 2 <= $crate::log::max_level() {
            println!("{} {} {}",
                " INFO".green(),
                format!("{}:", module_path!()).bright_black(),
                format_args!($($arg)*)
            );
        }
    }
}

#[macro_export]
macro_rules! debug {
    ($($arg:tt)*) => {
        if 3 <= $crate::log::max_level() {
            println!("{} {} {}",
                "DEBUG".bright_blue(),
                format!("{}:", module_path!()).bright_black(),
                format_args!($($arg)*)
            );
        }
    }
}

#[macro_export]
macro_rules! error {
    ($($arg:tt)*) => {
        if 1 <= $crate::log::max_level() {
            println!("{} {} {}",
                "ERROR".bright_red(),
                format!("{}:", module_path!()).bright_black(),
                format_args!($($arg)*)
            );
        }
    }
}