rnetmon/src/output.rs

54 lines
1.2 KiB
Rust

extern crate globset;
pub use std::collections::HashMap;
use globset::Glob;
use std::iter::Map;
use crate::message::*;
#[derive(Debug)]
pub struct Filter {
level: Level,
types: Vec<Glob>,
}
impl Filter {
fn new(config: &HashMap<String, serde_yaml::Value>) -> Self {
let mut globs = vec![];
let types = config
.get("types")
.expect("Missing types key")
.as_sequence()
.expect("types must be a list of strings")
.iter()
.map(|x| {
Glob::new(x.as_str().expect("filter must be a list of strings"))
.expect("Invalid glob pattern")
.compile_matcher()
})
.collect();
// let glob = Glob::new("*.rs")?.compile_matcher();
Filter {
level: config.get("level").to.unwrap_or(Level::Debug),
types: types,
}
}
// fn is_message_filtered(&self, message: Message) -> bool {
// if message.level < self.level{
// return true
// }
// if
// }
}
pub trait Output {
fn new(config: &HashMap<String, serde_yaml::Value>) -> Self
where
Self: Sized;
fn process_message(&mut self, message: Message);
}