Mercurial > crates > nonstick
comparison src/logging.rs @ 134:6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Instead of having to do a bunch of custom parsing and other logic
that tools often choke on, this change introduces an easy way
to depend upon custom #[cfg]s provided by the libpam-sys crate.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Thu, 03 Jul 2025 11:03:36 -0400 |
| parents | 80c07e5ab22f |
| children | efbc235f01d3 |
comparison
equal
deleted
inserted
replaced
| 133:32b2a545ca3e | 134:6c1e1bdb4164 |
|---|---|
| 13 //! | 13 //! |
| 14 //! A `PamShared` implementation may still use the `log` crate on the backend, | 14 //! A `PamShared` implementation may still use the `log` crate on the backend, |
| 15 //! and may even itself implement `log::Log`, but that interface is not exposed | 15 //! and may even itself implement `log::Log`, but that interface is not exposed |
| 16 //! to the generic PAM user. | 16 //! to the generic PAM user. |
| 17 | 17 |
| 18 use libpam_sys::cfg_pam_impl; | 18 #[cfg(pam_impl = "OpenPam")] |
| 19 | |
| 20 #[cfg_pam_impl("OpenPam")] | |
| 21 mod levels { | 19 mod levels { |
| 22 pub const ERROR: i32 = libpam_sys::PAM_LOG_ERROR; | 20 pub const ERROR: i32 = libpam_sys::PAM_LOG_ERROR; |
| 23 pub const WARN: i32 = libpam_sys::PAM_LOG_NOTICE; | 21 pub const WARN: i32 = libpam_sys::PAM_LOG_NOTICE; |
| 24 pub const INFO: i32 = libpam_sys::PAM_LOG_VERBOSE; | 22 pub const INFO: i32 = libpam_sys::PAM_LOG_VERBOSE; |
| 25 pub const DEBUG: i32 = libpam_sys::PAM_LOG_DEBUG; | 23 pub const DEBUG: i32 = libpam_sys::PAM_LOG_DEBUG; |
| 26 } | 24 } |
| 27 #[cfg_pam_impl(not("OpenPam"))] | 25 #[cfg(not(pam_impl = "OpenPam"))] |
| 28 mod levels { | 26 mod levels { |
| 29 pub const ERROR: i32 = libc::LOG_ERR; | 27 pub const ERROR: i32 = libc::LOG_ERR; |
| 30 pub const WARN: i32 = libc::LOG_WARNING; | 28 pub const WARN: i32 = libc::LOG_WARNING; |
| 31 pub const INFO: i32 = libc::LOG_INFO; | 29 pub const INFO: i32 = libc::LOG_INFO; |
| 32 pub const DEBUG: i32 = libc::LOG_DEBUG; | 30 pub const DEBUG: i32 = libc::LOG_DEBUG; |
| 168 /// ```no_run | 166 /// ```no_run |
| 169 /// # fn _test(pam_handle: impl nonstick::PamShared) { | 167 /// # fn _test(pam_handle: impl nonstick::PamShared) { |
| 170 /// # let userinfo_url = "https://zombo.com/"; | 168 /// # let userinfo_url = "https://zombo.com/"; |
| 171 /// nonstick::debug!(pam_handle, "making HTTP GET request to {userinfo_url}"); | 169 /// nonstick::debug!(pam_handle, "making HTTP GET request to {userinfo_url}"); |
| 172 /// // Will log a message like | 170 /// // Will log a message like |
| 173 /// // making HTTP GET request to https://zombo.com/" | 171 /// // "making HTTP GET request to https://zombo.com/" |
| 174 /// // at DEBUG level on syslog. | 172 /// // at DEBUG level on syslog. |
| 175 /// # } | 173 /// # } |
| 176 /// ``` | 174 /// ``` |
| 177 #[macro_export] | 175 #[macro_export] |
| 178 macro_rules! debug { ($handle:expr, $($arg:tt)+) => { $crate::__log_internal!($handle, Debug, $($arg)+);}} | 176 macro_rules! debug { ($handle:expr, $($arg:tt)+) => { $crate::__log_internal!($handle, Debug, $($arg)+);}} |
