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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#[macro_export]
macro_rules! log {
(target: $target:expr, $lvl:expr, $($arg:tt)+) => ({
static LOC: $crate::LogLocation = $crate::LogLocation {
__line: line!(),
__file: file!(),
__module_path: module_path!(),
};
let lvl = $lvl;
if !cfg!(log_level = "off") &&
(lvl <= $crate::LogLevel::Error || !cfg!(log_level = "error")) &&
(lvl <= $crate::LogLevel::Warn || !cfg!(log_level = "warn")) &&
(lvl <= $crate::LogLevel::Debug || !cfg!(log_level = "debug")) &&
(lvl <= $crate::LogLevel::Info || !cfg!(log_level = "info")) &&
lvl <= $crate::max_log_level() {
$crate::__log(lvl, $target, &LOC, format_args!($($arg)+))
}
});
($lvl:expr, $($arg:tt)+) => (log!(target: module_path!(), $lvl, $($arg)+))
}
#[macro_export]
macro_rules! error {
(target: $target:expr, $($arg:tt)*) => (
log!(target: $target, $crate::LogLevel::Error, $($arg)*);
);
($($arg:tt)*) => (
log!($crate::LogLevel::Error, $($arg)*);
)
}
#[macro_export]
macro_rules! warn {
(target: $target:expr, $($arg:tt)*) => (
log!(target: $target, $crate::LogLevel::Warn, $($arg)*);
);
($($arg:tt)*) => (
log!($crate::LogLevel::Warn, $($arg)*);
)
}
#[macro_export]
macro_rules! info {
(target: $target:expr, $($arg:tt)*) => (
log!(target: $target, $crate::LogLevel::Info, $($arg)*);
);
($($arg:tt)*) => (
log!($crate::LogLevel::Info, $($arg)*);
)
}
#[macro_export]
macro_rules! debug {
(target: $target:expr, $($arg:tt)*) => (
log!(target: $target, $crate::LogLevel::Debug, $($arg)*);
);
($($arg:tt)*) => (
log!($crate::LogLevel::Debug, $($arg)*);
)
}
#[macro_export]
macro_rules! trace {
(target: $target:expr, $($arg:tt)*) => (
log!(target: $target, $crate::LogLevel::Trace, $($arg)*);
);
($($arg:tt)*) => (
log!($crate::LogLevel::Trace, $($arg)*);
)
}
#[macro_export]
macro_rules! log_enabled {
(target: $target:expr, $lvl:expr) => ({
let lvl = $lvl;
!cfg!(log_level = "off") &&
(lvl <= $crate::LogLevel::Error || !cfg!(log_level = "error")) &&
(lvl <= $crate::LogLevel::Warn || !cfg!(log_level = "warn")) &&
(lvl <= $crate::LogLevel::Debug || !cfg!(log_level = "debug")) &&
(lvl <= $crate::LogLevel::Info || !cfg!(log_level = "info")) &&
lvl <= $crate::max_log_level() &&
$crate::__enabled(lvl, $target)
});
($lvl:expr) => (log_enabled!(target: module_path!(), $lvl))
}