2022-04-26 09:16:48 -04:00
|
|
|
// LogThru
|
|
|
|
// Pass errors through and log them simultaneously via map_err()
|
|
|
|
// Also contains common log facilities (net, rpc, rtab, pstore, crypto, etc )
|
|
|
|
|
2022-11-26 21:37:23 -05:00
|
|
|
use alloc::string::{String, ToString};
|
2021-12-17 19:18:25 -05:00
|
|
|
|
2021-12-16 21:57:28 -05:00
|
|
|
pub fn map_to_string<X: ToString>(arg: X) -> String {
|
|
|
|
arg.to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! fn_string {
|
|
|
|
($text:expr) => {
|
|
|
|
|| $text.to_string()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! log_net {
|
|
|
|
(error $text:expr) => {error!(
|
|
|
|
target: "net",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
2021-12-17 19:18:25 -05:00
|
|
|
(error $fmt:literal, $($arg:expr),+) => {
|
|
|
|
error!(target:"net", $fmt, $($arg),+);
|
2021-12-16 21:57:28 -05:00
|
|
|
};
|
2022-01-05 12:01:02 -05:00
|
|
|
(warn $text:expr) => {warn!(
|
|
|
|
target: "net",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
|
|
|
(warn $fmt:literal, $($arg:expr),+) => {
|
|
|
|
warn!(target:"net", $fmt, $($arg),+);
|
|
|
|
};
|
2022-05-04 20:40:10 -04:00
|
|
|
(debug $text:expr) => {debug!(
|
|
|
|
target: "net",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
|
|
|
(debug $fmt:literal, $($arg:expr),+) => {
|
|
|
|
debug!(target:"net", $fmt, $($arg),+);
|
|
|
|
};
|
2021-12-16 21:57:28 -05:00
|
|
|
($text:expr) => {trace!(
|
|
|
|
target: "net",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
2021-12-17 19:18:25 -05:00
|
|
|
($fmt:literal, $($arg:expr),+) => {
|
|
|
|
trace!(target:"net", $fmt, $($arg),+);
|
2021-12-16 21:57:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! log_rpc {
|
|
|
|
(error $text:expr) => { error!(
|
|
|
|
target: "rpc",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
2021-12-17 19:18:25 -05:00
|
|
|
(error $fmt:literal, $($arg:expr),+) => {
|
|
|
|
error!(target:"rpc", $fmt, $($arg),+);
|
2021-12-16 21:57:28 -05:00
|
|
|
};
|
2022-01-05 12:01:02 -05:00
|
|
|
(warn $text:expr) => { warn!(
|
|
|
|
target: "rpc",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
|
|
|
(warn $fmt:literal, $($arg:expr),+) => {
|
|
|
|
warn!(target:"rpc", $fmt, $($arg),+);
|
|
|
|
};
|
2022-05-24 22:46:30 -04:00
|
|
|
(debug $text:expr) => { error!(
|
|
|
|
target: "rpc",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
|
|
|
(debug $fmt:literal, $($arg:expr),+) => {
|
|
|
|
debug!(target:"rpc", $fmt, $($arg),+);
|
|
|
|
};
|
2021-12-16 21:57:28 -05:00
|
|
|
($text:expr) => {trace!(
|
|
|
|
target: "rpc",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
2021-12-17 19:18:25 -05:00
|
|
|
($fmt:literal, $($arg:expr),+) => {
|
|
|
|
trace!(target:"rpc", $fmt, $($arg),+);
|
2021-12-16 21:57:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! log_rtab {
|
|
|
|
(error $text:expr) => { error!(
|
|
|
|
target: "rtab",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
2021-12-17 19:18:25 -05:00
|
|
|
(error $fmt:literal, $($arg:expr),+) => {
|
|
|
|
error!(target:"rtab", $fmt, $($arg),+);
|
2021-12-16 21:57:28 -05:00
|
|
|
};
|
2022-01-05 12:01:02 -05:00
|
|
|
(warn $text:expr) => { warn!(
|
|
|
|
target: "rtab",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
|
|
|
(warn $fmt:literal, $($arg:expr),+) => {
|
|
|
|
warn!(target:"rtab", $fmt, $($arg),+);
|
|
|
|
};
|
2022-05-24 17:13:52 -04:00
|
|
|
(debug $text:expr) => { debug!(
|
|
|
|
target: "rtab",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
|
|
|
(debug $fmt:literal, $($arg:expr),+) => {
|
|
|
|
debug!(target:"rtab", $fmt, $($arg),+);
|
|
|
|
};
|
2021-12-16 21:57:28 -05:00
|
|
|
($text:expr) => {trace!(
|
|
|
|
target: "rtab",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
2021-12-17 19:18:25 -05:00
|
|
|
($fmt:literal, $($arg:expr),+) => {
|
|
|
|
trace!(target:"rtab", $fmt, $($arg),+);
|
2021-12-16 21:57:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-26 09:16:48 -04:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! log_pstore {
|
|
|
|
(error $text:expr) => { error!(
|
|
|
|
target: "pstore",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
|
|
|
(error $fmt:literal, $($arg:expr),+) => {
|
|
|
|
error!(target:"pstore", $fmt, $($arg),+);
|
|
|
|
};
|
|
|
|
(warn $text:expr) => { warn!(
|
|
|
|
target: "pstore",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
|
|
|
(warn $fmt:literal, $($arg:expr),+) => {
|
|
|
|
warn!(target:"pstore", $fmt, $($arg),+);
|
|
|
|
};
|
|
|
|
($text:expr) => {trace!(
|
|
|
|
target: "pstore",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
|
|
|
($fmt:literal, $($arg:expr),+) => {
|
|
|
|
trace!(target:"pstore", $fmt, $($arg),+);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! log_crypto {
|
|
|
|
(error $text:expr) => { error!(
|
|
|
|
target: "crypto",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
|
|
|
(error $fmt:literal, $($arg:expr),+) => {
|
|
|
|
error!(target:"crypto", $fmt, $($arg),+);
|
|
|
|
};
|
|
|
|
(warn $text:expr) => { warn!(
|
|
|
|
target: "crypto",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
|
|
|
(warn $fmt:literal, $($arg:expr),+) => {
|
|
|
|
warn!(target:"crypto", $fmt, $($arg),+);
|
|
|
|
};
|
|
|
|
($text:expr) => {trace!(
|
|
|
|
target: "crypto",
|
|
|
|
"{}",
|
|
|
|
$text,
|
|
|
|
)};
|
|
|
|
($fmt:literal, $($arg:expr),+) => {
|
|
|
|
trace!(target:"crypto", $fmt, $($arg),+);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-16 21:57:28 -05:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! logthru_net {
|
|
|
|
($($level:ident)?) => {
|
|
|
|
logthru!($($level)? "net")
|
|
|
|
};
|
|
|
|
($($level:ident)? $text:literal) => {
|
|
|
|
logthru!($($level)? "net", $text)
|
|
|
|
};
|
2021-12-17 19:18:25 -05:00
|
|
|
($($level:ident)? $fmt:literal, $($arg:expr),+) => {
|
|
|
|
logthru!($($level)? "net", $fmt, $($arg),+)
|
2021-12-16 21:57:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! logthru_rpc {
|
|
|
|
($($level:ident)?) => {
|
|
|
|
logthru!($($level)? "rpc")
|
|
|
|
};
|
|
|
|
($($level:ident)? $text:literal) => {
|
|
|
|
logthru!($($level)? "rpc", $text)
|
|
|
|
};
|
2021-12-17 19:18:25 -05:00
|
|
|
($($level:ident)? $fmt:literal, $($arg:expr),+) => {
|
|
|
|
logthru!($($level)? "rpc", $fmt, $($arg),+)
|
2021-12-16 21:57:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! logthru_rtab {
|
|
|
|
($($level:ident)?) => {
|
|
|
|
logthru!($($level)? "rtab")
|
|
|
|
};
|
|
|
|
($($level:ident)? $text:literal) => {
|
|
|
|
logthru!($($level)? "rtab", $text)
|
|
|
|
};
|
2021-12-17 19:18:25 -05:00
|
|
|
($($level:ident)? $fmt:literal, $($arg:expr),+) => {
|
|
|
|
logthru!($($level)? "rtab", $fmt, $($arg),+)
|
2021-12-16 21:57:28 -05:00
|
|
|
}
|
|
|
|
}
|
2022-01-08 23:33:25 -05:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! logthru_pstore {
|
|
|
|
($($level:ident)?) => {
|
|
|
|
logthru!($($level)? "pstore")
|
|
|
|
};
|
|
|
|
($($level:ident)? $text:literal) => {
|
|
|
|
logthru!($($level)? "pstore", $text)
|
|
|
|
};
|
|
|
|
($($level:ident)? $fmt:literal, $($arg:expr),+) => {
|
|
|
|
logthru!($($level)? "pstore", $fmt, $($arg),+)
|
|
|
|
}
|
|
|
|
}
|
2022-02-06 21:18:42 -05:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! logthru_crypto {
|
|
|
|
($($level:ident)?) => {
|
|
|
|
logthru!($($level)? "crypto")
|
|
|
|
};
|
|
|
|
($($level:ident)? $text:literal) => {
|
|
|
|
logthru!($($level)? "crypto", $text)
|
|
|
|
};
|
|
|
|
($($level:ident)? $fmt:literal, $($arg:expr),+) => {
|
|
|
|
logthru!($($level)? "crypto", $fmt, $($arg),+)
|
|
|
|
}
|
|
|
|
}
|
2021-12-16 21:57:28 -05:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! logthru {
|
|
|
|
// error
|
|
|
|
(error $target:literal) => (|e__| {
|
|
|
|
error!(
|
|
|
|
target: $target,
|
2022-05-24 17:13:52 -04:00
|
|
|
"[{:?}]",
|
2021-12-16 21:57:28 -05:00
|
|
|
e__,
|
|
|
|
);
|
|
|
|
e__
|
|
|
|
});
|
|
|
|
(error $target:literal, $text:literal) => (|e__| {
|
|
|
|
error!(
|
|
|
|
target: $target,
|
2022-05-24 17:13:52 -04:00
|
|
|
"[{:?}] {}",
|
2021-12-16 21:57:28 -05:00
|
|
|
e__,
|
|
|
|
$text
|
|
|
|
);
|
|
|
|
e__
|
|
|
|
});
|
2021-12-17 19:18:25 -05:00
|
|
|
(error $target:literal, $fmt:literal, $($arg:expr),+) => (|e__| {
|
2021-12-16 21:57:28 -05:00
|
|
|
error!(
|
|
|
|
target: $target,
|
2022-05-24 17:13:52 -04:00
|
|
|
concat!("[{:?}] ", $fmt),
|
2021-12-16 21:57:28 -05:00
|
|
|
e__,
|
2021-12-17 19:18:25 -05:00
|
|
|
$($arg),+
|
2021-12-16 21:57:28 -05:00
|
|
|
);
|
|
|
|
e__
|
|
|
|
});
|
2022-01-05 12:01:02 -05:00
|
|
|
// warn
|
|
|
|
(warn $target:literal) => (|e__| {
|
|
|
|
warn!(
|
|
|
|
target: $target,
|
2022-05-24 17:13:52 -04:00
|
|
|
"[{:?}]",
|
2022-01-05 12:01:02 -05:00
|
|
|
e__,
|
|
|
|
);
|
|
|
|
e__
|
|
|
|
});
|
|
|
|
(warn $target:literal, $text:literal) => (|e__| {
|
|
|
|
warn!(
|
|
|
|
target: $target,
|
2022-05-24 17:13:52 -04:00
|
|
|
"[{:?}] {}",
|
2022-01-05 12:01:02 -05:00
|
|
|
e__,
|
|
|
|
$text
|
|
|
|
);
|
|
|
|
e__
|
|
|
|
});
|
|
|
|
(warn $target:literal, $fmt:literal, $($arg:expr),+) => (|e__| {
|
|
|
|
warn!(
|
|
|
|
target: $target,
|
2022-05-24 17:13:52 -04:00
|
|
|
concat!("[{:?}] ", $fmt),
|
2022-01-05 12:01:02 -05:00
|
|
|
e__,
|
|
|
|
$($arg),+
|
|
|
|
);
|
|
|
|
e__
|
|
|
|
});
|
2022-01-02 23:49:01 -05:00
|
|
|
// debug
|
|
|
|
(debug $target:literal) => (|e__| {
|
|
|
|
debug!(
|
|
|
|
target: $target,
|
2022-05-24 17:13:52 -04:00
|
|
|
"[{:?}]",
|
2022-01-02 23:49:01 -05:00
|
|
|
e__,
|
|
|
|
);
|
|
|
|
e__
|
|
|
|
});
|
|
|
|
(debug $target:literal, $text:literal) => (|e__| {
|
|
|
|
debug!(
|
|
|
|
target: $target,
|
2022-05-24 17:13:52 -04:00
|
|
|
"[{:?}] {}",
|
2022-01-02 23:49:01 -05:00
|
|
|
e__,
|
|
|
|
$text
|
|
|
|
);
|
|
|
|
e__
|
|
|
|
});
|
|
|
|
(debug $target:literal, $fmt:literal, $($arg:expr),+) => (|e__| {
|
|
|
|
debug!(
|
|
|
|
target: $target,
|
2022-05-24 17:13:52 -04:00
|
|
|
concat!("[{:?}] ", $fmt),
|
2022-01-02 23:49:01 -05:00
|
|
|
e__,
|
|
|
|
$($arg),+
|
|
|
|
);
|
|
|
|
e__
|
|
|
|
});
|
2021-12-16 21:57:28 -05:00
|
|
|
// trace
|
|
|
|
($target:literal) => (|e__| {
|
|
|
|
trace!(
|
|
|
|
target: $target,
|
2022-05-24 17:13:52 -04:00
|
|
|
"[{:?}]",
|
2021-12-16 21:57:28 -05:00
|
|
|
e__,
|
|
|
|
);
|
|
|
|
e__
|
|
|
|
});
|
|
|
|
($target:literal, $text:literal) => (|e__| {
|
|
|
|
trace!(
|
|
|
|
target: $target,
|
2022-05-24 17:13:52 -04:00
|
|
|
"[{:?}] {}",
|
2021-12-16 21:57:28 -05:00
|
|
|
e__,
|
|
|
|
$text
|
|
|
|
);
|
|
|
|
e__
|
|
|
|
});
|
2021-12-17 19:18:25 -05:00
|
|
|
($target:literal, $fmt:literal, $($arg:expr),+) => (|e__| {
|
2021-12-16 21:57:28 -05:00
|
|
|
trace!(
|
|
|
|
target: $target,
|
2022-05-24 17:13:52 -04:00
|
|
|
concat!("[{:?}] ", $fmt),
|
2021-12-16 21:57:28 -05:00
|
|
|
e__,
|
2021-12-17 19:18:25 -05:00
|
|
|
$($arg),+
|
2021-12-16 21:57:28 -05:00
|
|
|
);
|
|
|
|
e__
|
|
|
|
})
|
|
|
|
}
|