flogging 0.6.0

This is a fast, flexible logging crate, loosely based on the Java logging package: java.util.logging.
Documentation
//
// File Name:    iso8601_formatter.rs
// Directory:    src/handlers/formatters
// Project Name: flogging
//
// Copyright (C) 2025 Bradley Willcott
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This library (crate) is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library (crate) is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library (crate).  If not, see <https://www.gnu.org/licenses/>.
//

//!
//! # Iso8601 Formatter
//!

use std::fmt;
use crate::FormatTrait;

///
/// ISO 8601 / RFC 3339 date & time format.
///
/// Example:
/// ```text
/// 2001-07-08T00:34:60.026490+09:30
/// ```
/// 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()`][Iso8601Formatter::format] method.
///
/// ```ignore
/// format!("{dt:35} {mod_path}->{fn_name} [{level:7}] {message}");
/// ```
/// Sample output:
/// ```text
/// 2025-07-18T14:01:01.051532664+08:00 flogging->main [WARNING] Rain is wet!
/// ```
///
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct Iso8601Formatter {
    dt_fmt: String,
    fmt_string: String,
}

impl Iso8601Formatter {
    ///
    /// Creates a new instance of `Iso8601Formatter`.
    ///
    pub fn new() -> Self {
        Self {
            dt_fmt: "%+".to_string(),
            fmt_string: "{dt:35} {mod_path}->{fn_name} [{level:7}] {message}".to_string(),
        }
    }

    ///
    /// Returns the date/time format string.
    ///
    pub fn dt_fmt(&self) -> String {
        self.dt_fmt.clone()
    }

    ///
    /// Returns the primary format string.
    ///
    pub fn fmt_string(&self) -> String {
        self.fmt_string.clone()
    }
}

impl Default for Iso8601Formatter {
    fn default() -> Self {
        Self::new()
    }
}

impl fmt::Display for Iso8601Formatter {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "dt_fmt: \"{}\" - fmt_string: \"{}\"",
            self.dt_fmt, self.fmt_string
        )
    }
}

impl FormatTrait for Iso8601Formatter {
    fn format(&self, log_entry: &crate::LogEntry) -> String {
        self.ft_fmt(self.dt_fmt(), self.fmt_string(), log_entry)
    }
}