forensic_rs/logging/macros.rs
1
2/// Logs a message at the error level.
3/// ```rust
4/// use forensic_rs::error;
5/// error!("The artifact {} cannot be parsed", r"C:\Windows\Prefetch\POWERSHELL.EXE-AE8EDC9B.pf")
6/// ```
7#[macro_export(local_inner_macros)]
8macro_rules! error {
9 ($($arg:tt)+) => (log!($crate::logging::Level::Error, $($arg)+))
10}
11
12/// Logs a message at the warn level.
13/// ```rust
14/// use forensic_rs::warn;
15/// warn!("The artifact {} cannot be parsed", r"C:\Windows\Prefetch\POWERSHELL.EXE-AE8EDC9B.pf")
16/// ```
17#[macro_export(local_inner_macros)]
18macro_rules! warn {
19 ($($arg:tt)+) => (log!($crate::logging::Level::Warn, $($arg)+))
20}
21
22/// Logs a message at the info level.
23/// ```rust
24/// use forensic_rs::info;
25/// info!("The artifact {} cannot be parsed", r"C:\Windows\Prefetch\POWERSHELL.EXE-AE8EDC9B.pf")
26/// ```
27#[macro_export(local_inner_macros)]
28macro_rules! info {
29 ($($arg:tt)+) => (log!($crate::logging::Level::Info, $($arg)+))
30}
31/// Logs a message at the debug level.
32/// ```rust
33/// use forensic_rs::debug;
34/// debug!("The artifact {} cannot be parsed", r"C:\Windows\Prefetch\POWERSHELL.EXE-AE8EDC9B.pf")
35/// ```
36#[macro_export(local_inner_macros)]
37macro_rules! debug {
38 ($($arg:tt)+) => (log!($crate::logging::Level::Debug, $($arg)+))
39}
40/// Logs a message at the trace level.
41/// ```rust
42/// use forensic_rs::trace;
43/// trace!("The artifact {} cannot be parsed", r"C:\Windows\Prefetch\POWERSHELL.EXE-AE8EDC9B.pf")
44/// ```
45#[macro_export(local_inner_macros)]
46macro_rules! trace {
47 ($($arg:tt)+) => (log!($crate::logging::Level::Trace, $($arg)+))
48}
49
50/// Logs a message with the desired level
51/// ```rust
52/// use forensic_rs::log;
53/// use forensic_rs::logging::Level;
54/// log!(Level::Info, "The artifact {} cannot be parsed", r"C:\Windows\Prefetch\POWERSHELL.EXE-AE8EDC9B.pf")
55/// ```
56#[macro_export(local_inner_macros)]
57macro_rules! log {
58 ($lvl:expr, $($arg:tt)+) => ({
59 let lvl = $lvl;
60 if lvl <= $crate::logging::Level::Trace && lvl <= $crate::logging::max_level() {
61 let _ = $crate::logging::COMPONENT_LOGGER.with(|v| {
62 let msngr = v.borrow();
63 msngr.log(lvl, std::module_path!(), std::file!(), std::line!(), std::borrow::Cow::Owned(std::format!($($arg)+)));
64 });
65 }
66 });
67}