pub const LEVEL_INFO: i32 = 20;
pub const LEVEL_WARNING: i32 = 30;
pub const LEVEL_ERROR: i32 = 40;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LogData {
pub gateway_name: String,
pub msg: String,
pub level: i32,
}
impl Default for LogData {
fn default() -> Self {
Self {
gateway_name: String::new(),
msg: String::new(),
level: LEVEL_INFO,
}
}
}
impl LogData {
pub fn info(gateway_name: &str, msg: impl Into<String>) -> Self {
Self {
gateway_name: gateway_name.to_string(),
msg: msg.into(),
level: LEVEL_INFO,
}
}
pub fn is_warning_or_above(&self) -> bool {
self.level >= LEVEL_WARNING
}
}