quicklog_flush/
file_flusher.rs1use std::{
2 fs::OpenOptions,
3 io::{LineWriter, Write},
4};
5
6use crate::Flush;
7
8pub struct FileFlusher(&'static str);
10
11impl FileFlusher {
12 pub fn new(path: &'static str) -> FileFlusher {
14 FileFlusher(path)
15 }
16}
17
18impl Flush for FileFlusher {
19 fn flush_one(&mut self, display: String) {
20 match OpenOptions::new().create(true).append(true).open(self.0) {
21 Ok(file) => {
22 let mut writer = LineWriter::new(file);
23 match writer.write_all(display.as_bytes()) {
24 Ok(_) => (),
25 Err(_) => panic!("Unable to write to file"),
26 };
27 }
28 Err(_) => panic!("Unable to open file"),
29 }
30 }
31}