src/logger/log_entry.rs
Lines
100.00 %
Functions
100.00 %
Regions
100.00 %
| Line | Count | Source (jump to first uncovered line) |
|---|---|---|
| 1 | // | |
| 2 | // File Name: log_entry.rs | |
| 3 | // Directory: src/logger | |
| 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 | //! # Log Entry | |
| 26 | //! | |
| 27 | ||
| 28 | use ::{,}; | |
| 29 | use ::{, ::}; | |
| 30 | use super::Level; | |
| 31 | ||
| 32 | /// | |
| 33 | /// Used to provide relevant information about each log entry. | |
| 34 | /// | |
| 35 | #[derive()] | |
| 36 | pub struct LogEntry { | |
| 37 | pubtimestamp: <> | |
| 38 | pubmod_path: | |
| 39 | /// | |
| 40 | /// This is the name of the function/method inside which this | |
| 41 | /// log entry was generated. | |
| 42 | /// | |
| 43 | pubfn_name: | |
| 44 | publevel: | |
| 45 | pubmessage: | |
| 46 | } | |
| 47 | ||
| 48 | impl ::for LogEntry { | |
| 49 | 1 | fn fmt(&selff: &mut ::<_>) -> :: { |
| 50 | 1 | write!( |
| 51 | 1 | |
| 52 | 1 | "{} : {}->{} ({}) {}", |
| 53 | self, self, self, self, self | |
| 54 | ) | |
| 55 | 1 | } |
| 56 | } | |
| 57 | ||
| 58 | #[allow()] | |
| 59 | impl LogEntry { | |
| 60 | 109 | pub(crate) fn create(level:fn_name:message:) -> { |
| 61 | 109 | { |
| 62 | 109 | : ::(), |
| 63 | 109 | : String::(), |
| 64 | 109 | , |
| 65 | 109 | , |
| 66 | 109 | , |
| 67 | 109 | } |
| 68 | 109 | } |
| 69 | ||
| 70 | 2 | pub(crate) fn fn_name(&self) -> { |
| 71 | 2 | selfclone() |
| 72 | 2 | } |
| 73 | ||
| 74 | 9 | pub(crate) fn level(&self) -> { |
| 75 | 9 | self |
| 76 | 9 | } |
| 77 | ||
| 78 | 5 | pub(crate) fn message(&self) -> { |
| 79 | 5 | selfclone() |
| 80 | 5 | } |
| 81 | ||
| 82 | 1 | pub(crate) fn mod_path(&self) -> { |
| 83 | 1 | selfclone() |
| 84 | 1 | } |
| 85 | ||
| 86 | 1 | pub(crate) fn set_fn_name(&mut selffn_name:) { |
| 87 | 1 | self=clone(); |
| 88 | 1 | } |
| 89 | ||
| 90 | 105 | pub(crate) fn set_mod_path(&mut selfmod_path:) { |
| 91 | 105 | self=clone(); |
| 92 | 105 | } |
| 93 | ||
| 94 | 1 | pub(crate) fn timestamp(&self) -> <> { |
| 95 | 1 | self |
| 96 | 1 | } |
| 97 | } | |
| 98 | ||
| 99 | #[cfg()] | |
| 100 | mod tests { | |
| 101 | use super::*; | |
| 102 | ||
| 103 | #[test] | |
| 104 | 1 | fn to_string() { |
| 105 | 1 | let mut= |
| 106 | 1 | ::(::INFO, "to_string"to_string(), "message"to_string()); |
| 107 | ||
| 108 | 1 | set_mod_path(module_path!()to_owned()); |
| 109 | 1 | println!("\nlog_entry: {log_entry}\n"); |
| 110 | ||
| 111 | 1 | assert_eq!(level(), ::INFO); |
| 112 | 1 | assert_eq!(message(), "message"to_string()); |
| 113 | 1 | assert_eq!(fn_name(), "to_string"to_string()); |
| 114 | 1 | assert_eq!(mod_path(), module_path!()); |
| 115 | 1 | assert!(timestamp()timestamp() > 0); |
| 116 | ||
| 117 | 1 | set_fn_name("fn_name"to_owned()); |
| 118 | 1 | assert_eq!(fn_name(), "fn_name"to_string()); |
| 119 | 1 | } |
| 120 | } |