diff --git a/spdlog/src/logger.rs b/spdlog/src/logger.rs index 778cdae8..d934362f 100644 --- a/spdlog/src/logger.rs +++ b/spdlog/src/logger.rs @@ -1,4 +1,4 @@ -use std::{result::Result as StdResult, time::Duration}; +use std::{fmt::Debug, result::Result as StdResult, time::Duration}; use crate::{ env_level, @@ -115,6 +115,36 @@ pub struct Logger { periodic_flusher: Mutex>, } +impl Debug for Logger { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Logger") + .field("name", &self.name) + .field("level_filter", &self.level_filter()) + .field( + "sinks", + &self + .sinks + .iter() + .map(|sink| sink.level_filter()) + .collect::>(), + ) + .field("flush_level_filter", &self.flush_level_filter()) + .field("error_handler", &self.error_handler.read()) + .field( + "periodic_flusher", + &self + .periodic_flusher + .lock() + .as_deref() + .map(|opt| opt.as_ref().map(|(dur, _)| *dur)) + .as_ref() + .map(|dur| dur as &dyn Debug) + .unwrap_or(&"*lock is poisoned*"), + ) + .finish() + } +} + impl Logger { /// Gets a [`LoggerBuilder`] with default parameters: /// @@ -666,8 +696,7 @@ mod tests { #[test] fn send_sync() { - assert_send::(); - assert_sync::(); + assert_trait!(Logger: Send + Sync + Debug); } #[test] diff --git a/spdlog/src/test_utils/common.rs b/spdlog/src/test_utils/common.rs index 972c010c..4163a172 100644 --- a/spdlog/src/test_utils/common.rs +++ b/spdlog/src/test_utils/common.rs @@ -220,9 +220,16 @@ pub fn build_test_logger(cb: impl FnOnce(&mut LoggerBuilder) -> &mut LoggerBuild builder.build().unwrap() } -pub fn assert_send() {} - -pub fn assert_sync() {} +#[macro_export] +macro_rules! assert_trait { + ($type:ty: $($traits:tt)+) => {{ + fn __assert_trait() {} + __assert_trait::<$type>(); + }}; +} +#[doc(hidden)] +#[allow(unused_imports)] +pub use assert_trait; #[must_use] pub fn echo_logger_from_pattern(