.
//
//!
//! # UnixTimeStamp Formatter
//!
use ::fmt;
use crate::FormatTrait;
#[derive(,,,,)]
///
/// Unix Timestamp format.
///
/// The first part (before the decimal point) is
/// the number of seconds since 1970-01-01 00:00 UTC.
///
/// The second part is the number of nanoseconds since
/// the last whole second.
///
/// Example:
/// ```text
/// 1752817859.157970496
/// ```
/// Template:
/// - `dt` in the template would be the datetime string, similar to the above.
/// - `mod_path`, `fn_name`, `level`, and `message` all come out of the `LogEntry`
/// provided to the [`format()`][UnixTimestampFormatter::format] method.
///
/// ```ignore
/// format!("{dt} {mod_path}->{fn_name} [{level:7}] {message}");
/// ```
/// Sample output:
/// ```text
/// 1752818461.051538870 flogging->main [SEVERE ] Hurricanes are windy!
/// ```
///
pub struct UnixTimestampFormatter {
dt_fmt:
fmt_string:
}
impl UnixTimestampFormatter {
///
/// Creates a new instance of `UnixTimestampFormatter`.
///
pub fn new() -> Self {
Self {
: "%s.%f"to_string(),
: "{dt} {mod_path}->{fn_name} [{level:7}] {message}"to_string(),
}
}
///
/// Returns the date/time format string.
///
pub fn dt_fmt(&self) -> {
selfclone()
}
///
/// Returns the primary format string.
///
pub fn fmt_string(&self) -> {
selfclone()
}
}
impl for UnixTimestampFormatter {
fn default() -> Self {
Self::()
}
}
impl ::for UnixTimestampFormatter {
fn fmt(&selff: &mut ::<_>) -> :: {
write!(
"dt_fmt: \"{}\" - fmt_string: \"{}\"",
self, self
)
}
}
impl for UnixTimestampFormatter {
fn format(&selflog_entry: &::) -> {
selfft_fmt(selfdt_fmt(), selffmt_string(),)
}
}