Mercurial > crates > nonstick
comparison src/logging.rs @ 98:b87100c5eed4
Start on environment variables, and make pointers nicer.
This starts work on the PAM environment handling, and in so doing,
introduces the CHeapBox and CHeapString structs. These are analogous
to Box and CString, but they're located on the C heap rather than
being Rust-managed memory.
This is because environment variables deal with even more pointers
and it turns out we can lose a lot of manual freeing using homemade
smart pointers.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Tue, 24 Jun 2025 04:25:25 -0400 |
parents | 5ddbcada30f2 |
children | dfcd96a74ac4 |
comparison
equal
deleted
inserted
replaced
97:efe2f5f8b5b2 | 98:b87100c5eed4 |
---|---|
74 /// This supports `format!`-style formatting. | 74 /// This supports `format!`-style formatting. |
75 /// | 75 /// |
76 /// # Example | 76 /// # Example |
77 /// | 77 /// |
78 /// ```no_run | 78 /// ```no_run |
79 /// # let pam_handle: Box<dyn nonstick::PamShared> = unimplemented!(); | 79 /// # fn _test(pam_handle: impl nonstick::PamShared) { |
80 /// # let load_error = "xxx"; | 80 /// # let load_error = "xxx"; |
81 /// nonstick::error!(pam_handle, "error loading data from data source: {load_error}"); | 81 /// nonstick::error!(pam_handle, "error loading data from data source: {load_error}"); |
82 /// // Will log a message like "error loading data from data source: timed out" | 82 /// // Will log a message like "error loading data from data source: timed out" |
83 /// // at ERROR level on syslog. | 83 /// // at ERROR level on syslog. |
84 /// # } | |
84 /// ``` | 85 /// ``` |
85 #[macro_export] | 86 #[macro_export] |
86 macro_rules! error { ($handle:expr, $($arg:tt)+) => { $crate::__log_internal!($handle, Error, $($arg)+);}} | 87 macro_rules! error { ($handle:expr, $($arg:tt)+) => { $crate::__log_internal!($handle, Error, $($arg)+);}} |
87 | 88 |
88 /// Logs a message at warning level via the given PAM handle. | 89 /// Logs a message at warning level via the given PAM handle. |
90 /// This supports `format!`-style formatting. | 91 /// This supports `format!`-style formatting. |
91 /// | 92 /// |
92 /// # Example | 93 /// # Example |
93 /// | 94 /// |
94 /// ```no_run | 95 /// ```no_run |
95 /// # let pam_handle: Box<dyn nonstick::PamShared> = unimplemented!(); | 96 /// # fn _test(pam_handle: impl nonstick::PamShared) { |
96 /// # let latency_ms = "xxx"; | 97 /// # let latency_ms = "xxx"; |
97 /// nonstick::warn!(pam_handle, "loading took too long: {latency_ms} ms"); | 98 /// nonstick::warn!(pam_handle, "loading took too long: {latency_ms} ms"); |
98 /// // Will log a message like "loading took too long: 495 ms" | 99 /// // Will log a message like "loading took too long: 495 ms" |
99 /// // at WARN level on syslog. | 100 /// // at WARN level on syslog. |
101 /// # } | |
100 /// ``` | 102 /// ``` |
101 #[macro_export] | 103 #[macro_export] |
102 macro_rules! warn { ($handle:expr, $($arg:tt)+) => { $crate::__log_internal!($handle, Warning, $($arg)+);}} | 104 macro_rules! warn { ($handle:expr, $($arg:tt)+) => { $crate::__log_internal!($handle, Warning, $($arg)+);}} |
103 | 105 |
104 /// Logs a message at info level via the given PAM handle. | 106 /// Logs a message at info level via the given PAM handle. |
106 /// This supports `format!`-style formatting. | 108 /// This supports `format!`-style formatting. |
107 /// | 109 /// |
108 /// # Example | 110 /// # Example |
109 /// | 111 /// |
110 /// ```no_run | 112 /// ```no_run |
111 /// # let pam_handle: Box<dyn nonstick::PamShared> = unimplemented!(); | 113 /// # fn _test(pam_handle: impl nonstick::PamShared) { |
112 /// nonstick::info!(pam_handle, "using remote backend to load user data"); | 114 /// nonstick::info!(pam_handle, "using remote backend to load user data"); |
113 /// // Will log a message like "using remote backend to load user data" | 115 /// // Will log a message like "using remote backend to load user data" |
114 /// // at INFO level on syslog. | 116 /// // at INFO level on syslog. |
117 /// # } | |
115 /// ``` | 118 /// ``` |
116 #[macro_export] | 119 #[macro_export] |
117 macro_rules! info { ($handle:expr, $($arg:tt)+) => { $crate::__log_internal!($handle, Info, $($arg)+);}} | 120 macro_rules! info { ($handle:expr, $($arg:tt)+) => { $crate::__log_internal!($handle, Info, $($arg)+);}} |
118 | 121 |
119 /// Logs a message at debug level via the given PAM handle. | 122 /// Logs a message at debug level via the given PAM handle. |
122 /// This supports `format!`-style formatting. | 125 /// This supports `format!`-style formatting. |
123 /// | 126 /// |
124 /// # Example | 127 /// # Example |
125 /// | 128 /// |
126 /// ```no_run | 129 /// ```no_run |
127 /// # let pam_handle: Box<dyn nonstick::PamShared> = unimplemented!(); | 130 /// # fn _test(pam_handle: impl nonstick::PamShared) { |
128 /// # let userinfo_url = "https://zombo.com/"; | 131 /// # let userinfo_url = "https://zombo.com/"; |
129 /// nonstick::debug!(pam_handle, "making HTTP GET request to {userinfo_url}"); | 132 /// nonstick::debug!(pam_handle, "making HTTP GET request to {userinfo_url}"); |
130 /// // Will log a message like | 133 /// // Will log a message like |
131 /// // "pam_http/lib.rs:39:14: making HTTP GET request to https://zombo.com/" | 134 /// // "pam_http/lib.rs:39:14: making HTTP GET request to https://zombo.com/" |
132 /// // at DEBUG level on syslog. | 135 /// // at DEBUG level on syslog. |
136 /// # } | |
133 /// ``` | 137 /// ``` |
134 #[macro_export] | 138 #[macro_export] |
135 macro_rules! debug {($handle:expr, $($arg:tt)+) => { | 139 macro_rules! debug {($handle:expr, $($arg:tt)+) => { |
136 $crate::__log_internal!( | 140 $crate::__log_internal!( |
137 $handle, Debug, | 141 $handle, Debug, |