src/handlers/formatters/mod.rs
Lines
100.00 %
Functions
100.00 %
Regions
100.00 %
| Line | Count | Source |
|---|---|---|
| 1 | // | |
| 2 | // File Name: mod.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 | //! # Formatter | |
| 26 | //! | |
| 27 | ||
| 28 | // #![allow(unused)] | |
| 29 | ||
| 30 | mod format_trait; | |
| 31 | mod format_type; | |
| 32 | mod formatter; | |
| 33 | mod iso8601_formatter; | |
| 34 | mod mock_formatter; | |
| 35 | mod simple_formatter; | |
| 36 | mod unixtimestamp_formatter; | |
| 37 | ||
| 38 | use crate::LogEntry; | |
| 39 | pub use ::FormatTrait; | |
| 40 | pub use ::FormatType; | |
| 41 | pub use ::Formatter; | |
| 42 | pub use ::Iso8601Formatter; | |
| 43 | pub use ::MockFormatter; | |
| 44 | pub use ::SimpleFormatter; | |
| 45 | pub use ::UnixTimestampFormatter; | |
| 46 | ||
| 47 | #[cfg()] | |
| 48 | mod test { | |
| 49 | use ::::{Result,}; | |
| 50 | // use super::*; | |
| 51 | use crate::{::*, *}; | |
| 52 | use ::; | |
| 53 | ||
| 54 | #[test] | |
| 55 | 1 | fn iso8601() { |
| 56 | 1 | let= "^ |
| 57 | 1 | dt_fmt: \"%\\+\" - fmt_string: \"\\{dt:35} \\{mod_path}->\\{fn_name} \\[\\{level:7}] \\{message}\" |
| 58 | 1 | (?:\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{9}\\+\\d{2}:\\d{2}) ->iso8601 \\[INFO ] This is a test message |
| 59 | 1 | $"; |
| 60 | ||
| 61 | 1 | let= ::()unwrap(); |
| 62 | 1 | let mut= Vec::(); |
| 63 | ||
| 64 | 1 | let= ::( |
| 65 | 1 | INFO, |
| 66 | 1 | "iso8601"to_string(), |
| 67 | 1 | "This is a test message"to_string(), |
| 68 | ); | |
| 69 | ||
| 70 | 1 | let= ::create(None); |
| 71 | 1 | let=format(&); |
| 72 | // println!("\n{f:width$}\n{fs}", width = f.width()); | |
| 73 | 1 | writeln!( "\n{f:width$}\n{fs}",=width())expect("writeln!() failed"); |
| 74 | 1 | let= String::()unwrap(); |
| 75 | // println!("{result}",); | |
| 76 | ||
| 77 | 1 | assert!(is_match(&)); |
| 78 | 1 | } |
| 79 | ||
| 80 | #[test] | |
| 81 | 1 | fn simple_formatter() { |
| 82 | 1 | let= " |
| 83 | 1 | dt_fmt: \"\" - fmt_string: \"{mod_path}->{fn_name} [{level:7}] {message}\" |
| 84 | 1 | ->simple_formatter [INFO ] This is a test message |
| 85 | 1 | " |
| 86 | 1 | to_string(); |
| 87 | ||
| 88 | 1 | let mut= Vec::(); |
| 89 | ||
| 90 | 1 | let= ::( |
| 91 | 1 | INFO, |
| 92 | 1 | "simple_formatter"to_string(), |
| 93 | 1 | "This is a test message"to_string(), |
| 94 | ); | |
| 95 | ||
| 96 | 1 | let= ::create(None); |
| 97 | 1 | let=format(&); |
| 98 | // println!("\n{f:width$} {fs}\n", width = f.width()); | |
| 99 | 1 | writeln!( "\n{f:width$}\n{fs}",=width())expect("writeln!() failed"); |
| 100 | ||
| 101 | 1 | assert_eq!(, String::()unwrap()); |
| 102 | 1 | } |
| 103 | ||
| 104 | #[test] | |
| 105 | 1 | fn unix_timestamp() { |
| 106 | 1 | let= "^ |
| 107 | 1 | dt_fmt: \"%s\\.%f\" - fmt_string: \"\\{dt} \\{mod_path}->\\{fn_name} \\[\\{level:7}] \\{message}\" |
| 108 | 1 | (?:\\d{10}\\.\\d{9}) ->unix_timestamp \\[INFO ] This is a test message |
| 109 | 1 | $"; |
| 110 | ||
| 111 | 1 | let= ::()unwrap(); |
| 112 | 1 | let mut= Vec::(); |
| 113 | ||
| 114 | 1 | let= ::( |
| 115 | 1 | INFO, |
| 116 | 1 | "unix_timestamp"to_string(), |
| 117 | 1 | "This is a test message"to_string(), |
| 118 | ); | |
| 119 | ||
| 120 | 1 | let= ::create(None); |
| 121 | 1 | let=format(&); |
| 122 | // println!("\n{f:width$}\n{fs}", width = f.width()); | |
| 123 | 1 | writeln!( "\n{f:width$}\n{fs}",=width())expect("writeln!() failed"); |
| 124 | 1 | let= String::()unwrap(); |
| 125 | // println!("{result}",); | |
| 126 | ||
| 127 | 1 | assert!(is_match(&)); |
| 128 | 1 | } |
| 129 | ||
| 130 | #[test] | |
| 131 | 1 | fn custom() { |
| 132 | 1 | let= "\nMockFormatter |
| 133 | 1 | MockFormatter |
| 134 | 1 | " |
| 135 | 1 | to_string(); |
| 136 | ||
| 137 | 1 | let mut= Vec::(); |
| 138 | ||
| 139 | 1 | let= ::( |
| 140 | 1 | INFO, |
| 141 | 1 | "custom"to_string(), |
| 142 | 1 | "Testing MockFormatter"to_string(), |
| 143 | ); | |
| 144 | 1 | let= ::create(Some(Box::(::()))); |
| 145 | 1 | let=format(&); |
| 146 | // println!("\n{f:width$}\n{fs}", width = f.width()); | |
| 147 | 1 | writeln!( "\n{f:width$}\n{fs}",=width())expect("writeln!() failed"); |
| 148 | ||
| 149 | 1 | assert_eq!(, String::()unwrap()); |
| 150 | 1 | } |
| 151 | } |