1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::fs::File;
use std::io::Write;
use std::boxed::Box;
use super::bridge_ilogger_trait::ILogger;
use super::bridge_loghelper::loghelper_formatlogline;
pub struct FileLogger {
filename: String,
file: File,
}
impl FileLogger {
pub fn new(filename: &str) -> Box<dyn ILogger> {
Box::new(FileLogger {
filename: filename.to_string(),
file: File::create(filename).unwrap(),
})
}
}
impl ILogger for FileLogger {
fn write_line(&mut self, loglevel:&str, message: &str) {
let output = loghelper_formatlogline(loglevel, message);
match self.file.write_all(output.as_bytes()) {
Ok(_) => { },
Err(ioerror) => {
eprintln!("Failed to write to file \"{}\": Error = {:#?}", self.filename, ioerror);
}
}
}
}