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
#![allow(unused_macros)]

use std::sync::atomic::{self, Ordering};

static VERBOSITY: atomic::AtomicUsize = atomic::AtomicUsize::new(0);

pub fn set_verbosity(verbosity: usize) {
    VERBOSITY.store(verbosity, Ordering::SeqCst);
}

pub fn get_verbosity() -> usize {
    VERBOSITY.load(Ordering::SeqCst)
}

#[doc(hidden)]
#[macro_export]
macro_rules! errorln {
    ($($arg:tt)*) => {
        if $crate::get_verbosity() >= 1 {
            eprintln!($($arg)*);
        }
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! warnln {
    ($($arg:tt)*) => {
        if $crate::get_verbosity() >= 2 {
            eprintln!($($arg)*);
        }
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! infoln {
    ($($arg:tt)*) => {
        if $crate::get_verbosity() >= 3 {
            eprintln!($($arg)*);
        }
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! debugln {
    ($($arg:tt)*) => {
        if $crate::get_verbosity() >= 4 {
            eprintln!($($arg)*);
        }
    };
}