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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use crate::appender::{Command, FastLogRecord, RecordFormat};
use log::LevelFilter;
pub struct FastLogFormat {
pub display_line_level: log::LevelFilter,
}
impl RecordFormat for FastLogFormat {
fn do_format(&self, arg: &mut FastLogRecord) -> String {
match &arg.command {
Command::CommandRecord => {
let data;
let now = fastdate::DateTime::now();
if arg.level.to_level_filter() <= self.display_line_level {
data = format!(
"{:29} {} {} - {} {}:{}\n",
&now,
arg.level,
arg.module_path,
arg.args,
arg.file,
arg.line.unwrap_or_default()
);
} else {
data = format!(
"{:29} {} {} - {}\n",
&now, arg.level, arg.module_path, arg.args
);
}
return data;
}
Command::CommandExit => {}
Command::CommandFlush(_) => {}
}
return String::new();
}
}
impl FastLogFormat {
pub fn new() -> FastLogFormat {
Self {
display_line_level: LevelFilter::Warn,
}
}
pub fn set_display_line_level(mut self, level: LevelFilter) -> Self {
self.display_line_level = level;
self
}
}
pub struct FastLogFormatJson {}
impl RecordFormat for FastLogFormatJson {
fn do_format(&self, arg: &mut FastLogRecord) -> String {
match &arg.command {
Command::CommandRecord => {
let now = fastdate::DateTime::now();
let js = format!(
"{}\"args\":\"{}\",\"date\":\"{}\",\"file\":\"{}\",\"level\":\"{}\",\"line\":{}{}",
"{",
arg.args,
now,
arg.file,
arg.level,
arg.line.unwrap_or_default(),
"}\n"
);
return js;
}
Command::CommandExit => {}
Command::CommandFlush(_) => {}
}
return String::new();
}
}
impl FastLogFormatJson {
pub fn new() -> FastLogFormatJson {
Self {}
}
}