use std::fmt;
use crate::FormatTrait;
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct SimpleFormatter {
dt_fmt: String,
fmt_string: String,
}
impl SimpleFormatter {
pub fn new() -> Self {
Self {
dt_fmt: "".to_string(),
fmt_string: "{mod_path}->{fn_name} [{level:7}] {message}".to_string(),
}
}
pub fn dt_fmt(&self) -> String {
self.dt_fmt.clone()
}
pub fn fmt_string(&self) -> String {
self.fmt_string.clone()
}
}
impl Default for SimpleFormatter {
fn default() -> Self {
Self::new()
}
}
impl fmt::Display for SimpleFormatter {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"dt_fmt: \"{}\" - fmt_string: \"{}\"",
self.dt_fmt, self.fmt_string
)
}
}
impl FormatTrait for SimpleFormatter {
fn format(&self, log_entry: &crate::LogEntry) -> String {
self.ft_fmt(self.dt_fmt(), self.fmt_string(), log_entry)
}
}