1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
use crate::record::LogRecord;
use crate::Format;
use std::io::BufRead;
pub fn process_stdin(format: Format, level_filter: u8, strict: bool) {
let stdin = std::io::stdin();
for line in stdin.lock().lines() {
let line = line.unwrap();
match serde_json::from_str::<LogRecord>(&line) {
Ok(r) => {
if r.level >= level_filter {
print!("{}", r.format(format))
}
}
Err(_) => {
if !strict {
println!("{}", line)
}
}
}
}
}