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
#[cfg(feature="timestamp")]
#[inline(always)]
fn get_date() -> impl core::fmt::Display {
struct TimeDate(time::PrimitiveDateTime);
impl core::fmt::Display for TimeDate {
#[inline(always)]
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "{}-{:02}-{:02} {:02}:{:02}:{:02}", self.0.year(), self.0.month(), self.0.day(), self.0.hour(), self.0.minute(), self.0.second())
}
}
TimeDate(std::time::SystemTime::now().into())
}
impl crate::Logger {
#[inline(always)]
pub fn print_fmt(args: core::fmt::Arguments<'_>) {
println!("{}", args);
}
#[inline]
pub fn print(record: &log::Record) {
#[cfg(feature="timestamp")]
{
println!("{:<5} [{}] {{{}:{}}} - {}",
record.level(),
get_date(),
record.file().unwrap_or("UNKNOWN"), record.line().unwrap_or(0),
record.args());
}
#[cfg(not(feature="timestamp"))]
{
println!("{:<5} {{{}:{}}} - {}",
record.level(),
record.file().unwrap_or("UNKNOWN"), record.line().unwrap_or(0),
record.args());
}
}
}