upend/src/util/mod.rs

36 lines
683 B
Rust
Raw Normal View History

pub mod exec;
pub mod hash;
pub mod jobs;
use log::debug;
2020-09-14 21:18:53 +02:00
#[derive(Default)]
pub struct LoggerSink {
pub buffer: Vec<u8>,
2020-09-14 21:18:53 +02:00
}
impl std::io::Write for LoggerSink {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.buffer.extend(buf.iter());
if self.buffer.ends_with(b"\n") {
self.flush()?;
}
Ok(buf.len())
}
fn flush(&mut self) -> std::io::Result<()> {
use std::str;
debug!(
"{}",
str::from_utf8(self.buffer.as_mut())
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?
.trim()
);
Ok(())
}
}