Mercurial > crates > nonstick
comparison src/logging.rs @ 118:39760dfc9b3b
Detect PAM library based only on system lib; rename minimal lib to XSso.
Also formats and assorted other cleanup.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Sun, 29 Jun 2025 20:13:03 -0400 |
| parents | a12706e42c9d |
| children | 98a624cacd82 |
comparison
equal
deleted
inserted
replaced
| 117:20f7712a6857 | 118:39760dfc9b3b |
|---|---|
| 45 Warning = levels::WARN, | 45 Warning = levels::WARN, |
| 46 Info = levels::INFO, | 46 Info = levels::INFO, |
| 47 Debug = levels::DEBUG, | 47 Debug = levels::DEBUG, |
| 48 } | 48 } |
| 49 | 49 |
| 50 /// The location of a log entry. | 50 /// The location of a log entry. Use [`location!`](crate::location!) to create this. |
| 51 #[derive(Clone, Copy, Debug, Default)] | 51 #[derive(Clone, Copy, Debug, Default)] |
| 52 #[non_exhaustive] | |
| 52 pub struct Location<'a> { | 53 pub struct Location<'a> { |
| 53 pub file: &'a str, | 54 pub file: &'a str, |
| 54 pub line: u32, | 55 pub line: u32, |
| 55 pub function: &'a str, | 56 pub function: &'a str, |
| 56 _more: (), | |
| 57 } | 57 } |
| 58 | 58 |
| 59 impl<'a> Location<'a> { | 59 impl<'a> Location<'a> { |
| 60 /// Creates a new location. Just use [`location!`](crate::location!) instead. | |
| 60 pub fn new(file: &'a str, line: u32, function: &'a str) -> Self { | 61 pub fn new(file: &'a str, line: u32, function: &'a str) -> Self { |
| 61 Self {file, line, function, _more: ()} | 62 Self { |
| 63 file, | |
| 64 line, | |
| 65 function, | |
| 66 } | |
| 62 } | 67 } |
| 63 } | 68 } |
| 64 | 69 |
| 65 /// The [`Location`] where this macro is inserted. | 70 /// The [`Location`] where this macro is inserted. |
| 66 #[doc(hidden)] | 71 #[doc(hidden)] |
| 67 #[macro_export] | 72 #[macro_export] |
| 68 macro_rules! location { | 73 macro_rules! location { |
| 69 () => { $crate::logging::Location::new(file!(), line!(), $crate::__function!()) } | 74 () => { |
| 75 $crate::logging::Location::new(file!(), line!(), $crate::__function!()) | |
| 76 }; | |
| 70 } | 77 } |
| 71 | 78 |
| 72 /// Here's the guts of the logger thingy. You shouldn't be using this! | 79 /// Here's the guts of the logger thingy. You shouldn't be using this! |
| 73 #[doc(hidden)] | 80 #[doc(hidden)] |
| 74 #[macro_export] | 81 #[macro_export] |
| 88 fn p() {} | 95 fn p() {} |
| 89 fn f<T>(_: T) -> &'static str { | 96 fn f<T>(_: T) -> &'static str { |
| 90 ::std::any::type_name::<T>() | 97 ::std::any::type_name::<T>() |
| 91 } | 98 } |
| 92 f(p).trim_end_matches("::p") | 99 f(p).trim_end_matches("::p") |
| 93 }} | 100 }}; |
| 94 } | 101 } |
| 95 | 102 |
| 96 /// Logs a message at error level via the given PAM handle. | 103 /// Logs a message at error level via the given PAM handle. |
| 97 /// | 104 /// |
| 98 /// This supports `format!`-style formatting. | 105 /// This supports `format!`-style formatting. |
