src/handlers/formatters/simple_formatter.rs
Lines
100.00 %
Functions
100.00 %
Regions
100.00 %
| Line | Count | Source |
|---|---|---|
| 1 | // | |
| 2 | // File Name: simple_formatter.rs | |
| 3 | // Directory: src/handlers/formatters | |
| 4 | // Project Name: flogging | |
| 5 | // | |
| 6 | // Copyright (C) 2025 Bradley Willcott | |
| 7 | // | |
| 8 | // SPDX-License-Identifier: GPL-3.0-or-later | |
| 9 | // | |
| 10 | // This library (crate) is free software: you can redistribute it and/or modify | |
| 11 | // it under the terms of the GNU General Public License as published by | |
| 12 | // the Free Software Foundation, either version 3 of the License, or | |
| 13 | // (at your option) any later version. | |
| 14 | // | |
| 15 | // This library (crate) is distributed in the hope that it will be useful, | |
| 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 | // GNU General Public License for more details. | |
| 19 | // | |
| 20 | // You should have received a copy of the GNU General Public License | |
| 21 | // along with this library (crate). If not, see <https://www.gnu.org/licenses/>. | |
| 22 | // | |
| 23 | ||
| 24 | //! | |
| 25 | //! # Simple Formatter | |
| 26 | //! | |
| 27 | ||
| 28 | use ::fmt; | |
| 29 | use crate::FormatTrait; | |
| 30 | ||
| 31 | /// | |
| 32 | /// Simple format. | |
| 33 | /// | |
| 34 | /// Template: | |
| 35 | /// - `mod_path`, `fn_name`, `level`, and `message` all come out of the `LogEntry` | |
| 36 | /// provided to the [`format()`][SimpleFormatter::format] method. | |
| 37 | /// ```ignore | |
| 38 | /// format!("{mod_path}->{fn_name} [{level:7}] {message}"); | |
| 39 | /// ``` | |
| 40 | /// Sample output: | |
| 41 | /// ```text | |
| 42 | /// flogging->main [INFO ] It is cloudy today. | |
| 43 | /// ``` | |
| 44 | /// | |
| 45 | ||
| 46 | #[derive(,,,,)] | |
| 47 | pub struct SimpleFormatter { | |
| 48 | dt_fmt: | |
| 49 | fmt_string: | |
| 50 | } | |
| 51 | ||
| 52 | impl SimpleFormatter { | |
| 53 | /// | |
| 54 | /// Creates a new instance of `SimpleFormatter`. | |
| 55 | /// | |
| 56 | 52 | pub fn new() -> Self { |
| 57 | 52 | Self { |
| 58 | 52 | : ""to_string(), |
| 59 | 52 | : "{mod_path}->{fn_name} [{level:7}] {message}"to_string(), |
| 60 | 52 | } |
| 61 | 52 | } |
| 62 | ||
| 63 | /// | |
| 64 | /// Returns the date/time format string. | |
| 65 | /// | |
| 66 | 92 | pub fn dt_fmt(&self) -> { |
| 67 | 92 | selfclone() |
| 68 | 92 | } |
| 69 | ||
| 70 | /// | |
| 71 | /// Returns the primary format string. | |
| 72 | /// | |
| 73 | 92 | pub fn fmt_string(&self) -> { |
| 74 | 92 | selfclone() |
| 75 | 92 | } |
| 76 | } | |
| 77 | ||
| 78 | impl for SimpleFormatter { | |
| 79 | 50 | fn default() -> Self { |
| 80 | 50 | Self::() |
| 81 | 50 | } |
| 82 | } | |
| 83 | ||
| 84 | impl ::for SimpleFormatter { | |
| 85 | 18 | fn fmt(&selff: &mut ::<_>) -> :: { |
| 86 | 18 | write!( |
| 87 | 18 | |
| 88 | 18 | "dt_fmt: \"{}\" - fmt_string: \"{}\"", |
| 89 | self, self | |
| 90 | ) | |
| 91 | 18 | } |
| 92 | } | |
| 93 | ||
| 94 | impl for SimpleFormatter { | |
| 95 | 92 | fn format(&selflog_entry: &::) -> { |
| 96 | 92 | selfft_fmt(selfdt_fmt(), selffmt_string(),) |
| 97 | 92 | } |
| 98 | } |