1use std::fs::{File, OpenOptions};
2
3use crate::TuiLoggerLevelOutput;
4
5pub struct TuiLoggerFile {
7 pub dump: File,
8 pub format_separator: char,
9 pub timestamp_fmt: Option<String>,
10 pub format_output_target: bool,
11 pub format_output_file: bool,
12 pub format_output_line: bool,
13 pub format_output_level: Option<TuiLoggerLevelOutput>,
14}
15
16impl TuiLoggerFile {
17 pub fn new(fname: &str) -> Self {
18 TuiLoggerFile {
19 dump: OpenOptions::new()
20 .create(true)
21 .append(true)
22 .open(fname)
23 .expect("Failed to open dump File"),
24 format_separator: ':',
25 timestamp_fmt: Some("[%Y:%m:%d %H:%M:%S]".to_string()),
26 format_output_file: true,
27 format_output_line: true,
28 format_output_target: true,
29 format_output_level: Some(TuiLoggerLevelOutput::Long),
30 }
31 }
32 pub fn output_target(mut self, enabled: bool) -> Self {
33 self.format_output_target = enabled;
34 self
35 }
36 pub fn output_file(mut self, enabled: bool) -> Self {
37 self.format_output_file = enabled;
38 self
39 }
40 pub fn output_line(mut self, enabled: bool) -> Self {
41 self.format_output_line = enabled;
42 self
43 }
44 pub fn output_timestamp(mut self, fmt: Option<String>) -> Self {
45 self.timestamp_fmt = fmt;
46 self
47 }
48 pub fn output_separator(mut self, sep: char) -> Self {
49 self.format_separator = sep;
50 self
51 }
52 pub fn output_level(mut self, level: Option<TuiLoggerLevelOutput>) -> Self {
53 self.format_output_level = level;
54 self
55 }
56}