use super::types::FieldSemantic;
#[derive(Debug)]
pub struct LogSchema {
pub name: &'static str,
pub detect_keys: &'static [&'static str],
pub timestamp_keys: &'static [&'static str],
pub level_keys: &'static [&'static str],
pub target_keys: &'static [&'static str],
pub message_keys: &'static [&'static str],
pub extra_semantics: &'static [(&'static str, FieldSemantic)],
pub level_transform: Option<fn(&str) -> Option<&'static str>>,
pub keep_visible_extras: &'static [&'static str],
}
impl LogSchema {
pub fn classify_key(&self, key: &str) -> FieldSemantic {
if self.timestamp_keys.contains(&key) {
return FieldSemantic::Timestamp;
}
if self.level_keys.contains(&key) {
return FieldSemantic::Level;
}
if self.target_keys.contains(&key) {
return FieldSemantic::Target;
}
if self.message_keys.contains(&key) {
return FieldSemantic::Message;
}
for (k, sem) in self.extra_semantics {
if *k == key {
return *sem;
}
}
FieldSemantic::Extra
}
pub fn matches_detect_keys(&self, keys: &[&str]) -> bool {
if self.detect_keys.is_empty() {
return true;
}
self.detect_keys.iter().all(|dk| keys.contains(dk))
}
}