Repository navigation
Expand file tree
/
Copy pathlogger.rs
More file actions
85 lines (72 loc) · 1.79 KB
/
Copy pathlogger.rs
File metadata and controls
85 lines (72 loc) · 1.79 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use crate::environment;
use std::sync::LazyLock;
#[derive(PartialEq, PartialOrd)]
pub enum Verbosity {
Silent,
Error,
Warning,
Info,
Debug,
}
// TODO: const DEFAULT_VERBOSITY: Verbosity = Verbosity::Error;
const DEFAULT_VERBOSITY: Verbosity = Verbosity::Info;
const fn level_to_verbosity(level: Option<usize>) -> Verbosity {
match level {
Some(0) => Verbosity::Silent,
Some(1) => Verbosity::Error,
Some(2) => Verbosity::Warning,
Some(3) => Verbosity::Info,
Some(_) => Verbosity::Debug,
_ => DEFAULT_VERBOSITY,
}
}
pub struct Logger {
pub verbosity: Verbosity,
}
impl Logger {
const fn new(level: Option<usize>) -> Logger {
Logger {
verbosity: level_to_verbosity(level),
}
}
}
fn create_log() -> Logger {
let level = environment::get_optional(environment::CODEQL_EXTRACTOR_CPP_VERBOSITY)
.and_then(|s| s.parse().ok());
Logger::new(level)
}
pub static GLOBAL_LOGGER: LazyLock<Logger> = std::sync::LazyLock::new(create_log);
macro_rules! log {
($level:expr, $($arg:tt)*) => {
if $level <= crate::logger::GLOBAL_LOGGER.verbosity {
println!($($arg)*);
}
}
}
#[allow(unused_macros)]
macro_rules! debug {
($($arg:tt)*) => {
log!(crate::logger::Verbosity::Debug, $($arg)*);
}
}
macro_rules! info {
($($arg:tt)*) => {
log!(crate::logger::Verbosity::Info, $($arg)*);
}
}
macro_rules! warning {
($($arg:tt)*) => {
log!(crate::logger::Verbosity::Warning, $($arg)*);
}
}
macro_rules! error {
($($arg:tt)*) => {
log!(crate::logger::Verbosity::Error, $($arg)*);
}
}
#[allow(unused_imports)]
pub(crate) use debug;
pub(crate) use error;
pub(crate) use info;
pub(crate) use log;
pub(crate) use warning;