.
//
//!
//! # Format Trait
//!
use crate::LogEntry;
use ::DynClone;
use ::AsStrFormatExt;
use ::Regex;
use ::{,};
use ::strfmt;
///
/// Provides methods for formatting [`LogEntry`]s.
///
pub trait FormatTrait{
///
/// Use this method to setup the parameters for calling [`ft_fmt()`][FormatTrait::ft_fmt()].
///
/// ## Parameters
/// - `log_entry` A reference to the `LogEntry` to be formatted.
///
/// ## Examples
/// ```text
/// impl FormatTrait for SimpleFormatter {
/// fn format(&self, log_entry: &LogEntry) -> String {
/// self.ft_fmt(self.dt_fmt(), self.fmt_string(), log_entry)
/// }
/// }
/// ```
///
fn format(&selflog_entry: &) ->;
///
/// This method does the actual formatting of the `log_entry`.
///
/// ## Parameters
/// - `dt_fmt` - The [`chrono::DateTime`] format string.
/// - `fmt` - The primary format string.\
/// Available variables:
/// - `dt` - The datetime formatted with: `dt_fmt`.
/// - `mod_path` - The module path, possibly supplied via: [`module_path!()`][module_path].
/// - `fn_name` - The name of the function/method inside which the log entry
/// was generated. Supplied by the [`#[logger]`][crate::logger] macro, or manually with the
/// [`set_fn_name()`][crate::Logger::set_fn_name] method.
/// - `level` - The log [level][crate::Level] for which the entry was created.
/// - `message` - The text of the log entry.
///
fn ft_fmt(&selfdt_fmt:fmt:log_entry: &) -> {
let=format(&)to_string();
strfmt!(
&,
,
=>clone(),
=>clone(),
=>clone(),
=>as_str()
)
unwrap()
}
}
::clone_trait_object!();
impl ::for dyn FormatTrait {
fn fmt(&selff: &mut ::<_>) -> :: {
selffmt()
}
}
#[cfg()]
mod tests {
use crate::*;
use ::;
// use chrono::Local;
#[test]
fn strfmt_test() {
let= "test: {text} - {text2}";
let= "Some text";
let= "Will this work?";
let= strfmt!(,,)unwrap();
assert_eq!("test: Some text - Will this work?"to_string(),);
}
// #[test]
// fn format() {
// let log_entry = LogEntry {
// timestamp: Local::now(),
// mod_path: module_path!().to_string(),
// fn_name: "format".to_string(),
// level: crate::Level::INFO,
// message: "We are testing log entry formatting.".to_string(),
// };
// println! {"{log_entry}"};
// // let formatter =
// // let text =
// }
#[test]
fn debug() {
let= ::create(Some(Box::(::())));
println!("fmt: {fmt}");
let: <> = Box::(::());
println!("sf: {sf:?}");
assert_eq!(to_string(),to_string());
}
}