1#[macro_export]
13macro_rules! log {
14 ($level:expr, $($args:tt)+) => {{
16 const METADATA: $crate::Metadata = $crate::Metadata::new(
17 $level,
18 env!("CARGO_CRATE_NAME"),
19 module_path!(),
20 file!(),
21 line!(),
22 concat!(file!(), ':', line!()),
23 );
24
25 if METADATA.enabled() {
26 $crate::Event::dispatch(
27 &METADATA,
28 $crate::fmt_args!($($args)+),
29 $crate::schema!($($args)+),
30 );
31 }
32 }};
33}
34
35#[macro_export]
37macro_rules! trace {
38 ($($arg:tt)+) => {
39 $crate::log!($crate::Level::Trace, $($arg)+)
40 };
41}
42
43#[macro_export]
45macro_rules! debug {
46 ($($arg:tt)+) => {
47 $crate::log!($crate::Level::Debug, $($arg)+)
48 };
49}
50
51#[macro_export]
53macro_rules! info {
54 ($($arg:tt)+) => {
55 $crate::log!($crate::Level::Info, $($arg)+)
56 };
57}
58
59#[macro_export]
61macro_rules! warn {
62 ($($arg:tt)+) => {
63 $crate::log!($crate::Level::Warn, $($arg)+)
64 };
65}
66
67#[macro_export]
69macro_rules! error {
70 ($($arg:tt)+) => {
71 $crate::log!($crate::Level::Error, $($arg)+)
72 };
73}
74
75#[doc(hidden)]
76#[macro_export]
77macro_rules! schema {
78 (@ { $(,)* $($val:expr),* $(,)* } $(,)*) => {
82 &[ $($val),* ]
83 };
84
85 (@ { $(,)* $($out:expr),* }, $template:literal, $($args:tt)*) => {
91 $crate::schema!(
92 @ { $($out),* }
93 )
94 };
95 (@ { $(,)* $($out:expr),* }, $template:literal) => {
96 $crate::schema!(
97 @ { $($out),* }
98 )
99 };
100
101 (@ { $(,)* $($out:expr),* }, $($k:ident).+ = $val:expr, $($args:tt)*) => {
103 $crate::schema!(
104 @ { $($out),*, &$crate::KeyValue::new($crate::__log_stringify!($($k).+), $crate::Value::from_serde(&$val)) },
105 $($args)*
106 )
107 };
108
109 (@ { $(,)* $($out:expr),* }, $($k:ident).+ = $val:expr) => {
110 $crate::schema!(
111 @ { $($out),*, &$crate::KeyValue::new($crate::__log_stringify!($($k).+), $crate::Value::from_serde(&$val)) },
112 )
113 };
114
115 (@ { $(,)* $($out:expr),* }, $($k:ident).+ = ?$val:expr, $($args:tt)*) => {
117 $crate::schema!(
118 @ { $($out),*, &$crate::KeyValue::new($crate::__log_stringify!($($k).+), $crate::Value::from_debug(&$val)) },
119 $($args)*
120 )
121 };
122
123 (@ { $(,)* $($out:expr),* }, $($k:ident).+ = ?$val:expr) => {
124 $crate::schema!(
125 @ { $($out),*, &$crate::KeyValue::new($crate::__log_stringify!($($k).+), $crate::Value::from_debug($val)) },
126 )
127 };
128
129 (@ { $(,)* $($out:expr),* }, $($k:ident).+ = %$val:expr, $($args:tt)*) => {
131 $crate::schema!(
132 @ { $($out),*, &$crate::KeyValue::new($crate::__log_stringify!($($k).+), $crate::Value::from_display(&$val)) },
133 $($args)*
134 )
135 };
136
137 (@ { $(,)* $($out:expr),* }, $($k:ident).+ = %$val:expr) => {
138 $crate::schema!(
139 @ { $($out),*, &$crate::KeyValue::new($crate::__log_stringify!($($k).+), $crate::Value::from_display(&$val)) },
140 )
141 };
142
143 (@ { $(,)* $($out:expr),* }, $k:literal = $val:expr, $($args:tt)*) => {
145 $crate::schema!(
146 @ { $($out),*, &$crate::KeyValue::new($k, $crate::Value::from_serde(&$val)) },
147 $($args)*
148 )
149 };
150
151 (@ { $(,)* $($out:expr),* }, $k:literal = $val:expr) => {
152 $crate::schema!(
153 @ { $($out),*, &$crate::KeyValue::new($k, $crate::Value::from_serde(&$val)) },
154 )
155 };
156
157 (@ { $(,)* $($out:expr),* }, $k:literal = ?$val:expr, $($args:tt)*) => {
159 $crate::schema!(
160 @ { $($out),*, &$crate::KeyValue::new($k, $crate::Value::from_debug(&$val)) },
161 $($args)*
162 )
163 };
164
165 (@ { $(,)* $($out:expr),* }, $k:literal = ?$val:expr) => {
166 $crate::schema!(
167 @ { $($out),*, &$crate::KeyValue::new($k, $crate::Value::from_debug(&$val)) },
168 )
169 };
170
171 (@ { $(,)* $($out:expr),* }, $k:literal = %$val:expr, $($args:tt)*) => {
173 $crate::schema!(
174 @ { $($out),*, &$crate::KeyValue::new($k, $crate::Value::from_display(&$val)) },
175 $($args)*
176 )
177 };
178
179 (@ { $(,)* $($out:expr),* }, $k:literal = %$val:expr) => {
180 $crate::schema!(
181 @ { $($out),*, &$crate::KeyValue::new($k, $crate::Value::from_display(&$val)) },
182 )
183 };
184
185 (@ { $(,)* $($out:expr),* }, $schema:expr, $($args:tt)*) => {
187 $crate::schema!(
188 @ { $($out),*, &$schema },
189 $($args)*
190 )
191 };
192 (@ { $(,)* $($out:expr),* }, $schema:expr) => {
193 $crate::schema!(
194 @ { $($out),*, &$schema },
195 )
196 };
197
198 ($($args:tt)*) => {
202 $crate::schema!(@ { }, $($args)*)
203 };
204}
205
206#[doc(hidden)]
207#[macro_export]
208macro_rules! fmt_args {
209 () => {
213 None
214 };
215
216 ($template:literal, $($args:tt)*) => {
218 Some(::std::format_args!($template, $($args)*))
219 };
220 ($template:literal) => {
221 Some(::std::format_args!($template))
222 };
223
224 ($($k:ident).+ = $val:expr, $($args:tt)*) => {
226 $crate::fmt_args!(
227 $($args)*
228 )
229 };
230 ($($k:ident).+ = $val:expr) => {
231 $crate::fmt_args!()
232 };
233 ($($k:ident).+ = ?$val:expr, $($args:tt)*) => {
235 $crate::fmt_args!(
236 $($args)*
237 )
238 };
239 ($($k:ident).+ = ?$val:expr) => {
240 $crate::fmt_args!()
241 };
242 ($($k:ident).+ = %$val:expr, $($args:tt)*) => {
244 $crate::fmt_args!(
245 $($args)*
246 )
247 };
248 ($($k:ident).+ = %$val:expr) => {
249 $crate::fmt_args!()
250 };
251
252 ($k:literal = $val:expr, $($args:tt)*) => {
254 $crate::fmt_args!(
255 $($args)*
256 )
257 };
258 ($k:literal = $val:expr) => {
259 $crate::fmt_args!()
260 };
261 ($k:literal = ?$val:expr, $($args:tt)*) => {
263 $crate::fmt_args!(
264 $($args)*
265 )
266 };
267 ($k:literal = ?$val:expr) => {
268 $crate::fmt_args!()
269 };
270 ($k:literal = %$val:expr, $($args:tt)*) => {
272 $crate::fmt_args!(
273 $($args)*
274 )
275 };
276 ($k:literal = %$val:expr) => {
277 $crate::fmt_args!()
278 };
279
280 ($schema:expr, $($args:tt)*) => {
282 $crate::fmt_args!(
283 $($args)*
284 )
285 };
286 ($schema:expr) => {
287 $crate::fmt_args!()
288 };
289}
290
291#[doc(hidden)]
292#[macro_export]
293macro_rules! __log_stringify {
294 ($s:expr) => {
295 stringify!($s)
296 };
297}