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
pub struct FlagsStyle {
/// Color to render the log message body;
pub body_style: console::Style,
/// Color to render the flag label;
pub label_style: console::Style,
/// Text for the log message flag label (ex: WARN, DEBUG, etc)
pub label: &'static str,
}
/// This trait defines the flags value used for gating logging messages. You
/// should define a new bitflags type and then implement this on it. See
/// `StandardFlags` for an example.
pub trait Flags: bitflags::Flags + Send + Sync + Copy + Eq {
fn style(self) -> FlagsStyle;
}
/// Turn key/values into a lambda for extending attributes, used in various log and
/// error functions.
#[macro_export]
macro_rules! ea{
($($k: ident = $v: expr), *) => {
| _attrs | {
$(_attrs.insert(stringify!($k), $v.to_string());) *
}
};
}
/// A helper to easily generate debug strings for types implementing `Debug`.
pub trait DebugDisplay {
fn dbg_str(&self) -> String;
fn pretty_dbg_str(&self) -> String;
}
impl<T: std::fmt::Debug> DebugDisplay for T {
fn dbg_str(&self) -> String {
return format!("{:?}", self);
}
fn pretty_dbg_str(&self) -> String {
return format!("{:#?}", self);
}
}