From 5b0c82cf2b88f4efe940a8dcfaeabf482e604adb Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sat, 7 Sep 2024 23:47:06 +0200 Subject: [PATCH] feat(log): specify span events + doc fixes --- members/libpt-log/src/error.rs | 2 +- members/libpt-log/src/lib.rs | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/members/libpt-log/src/error.rs b/members/libpt-log/src/error.rs index 8119790..0408d33 100644 --- a/members/libpt-log/src/error.rs +++ b/members/libpt-log/src/error.rs @@ -17,7 +17,7 @@ pub enum Error { /// Could not assign logger as the global default #[error("Could not assign logger as global default")] SetGlobalDefaultFail(#[from] SetGlobalDefaultError), - /// any other error type, wrapped in [anyhow::Error](anyhow::Error) + /// any other error type, wrapped in [anyhow::Error] #[error(transparent)] Other(#[from] anyhow::Error), } diff --git a/members/libpt-log/src/lib.rs b/members/libpt-log/src/lib.rs index e5f7f8b..8e882e1 100644 --- a/members/libpt-log/src/lib.rs +++ b/members/libpt-log/src/lib.rs @@ -61,7 +61,7 @@ static INITIALIZED: AtomicBool = AtomicBool::new(false); /// # } /// /// ``` -#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)] #[allow(clippy::struct_excessive_bools)] // it's just true/false values, not states, and I don't // need to reinvent the wheel pub struct LoggerBuilder { @@ -94,6 +94,8 @@ pub struct LoggerBuilder { show_time: bool, /// show timestamps as uptime (duration since the logger was initialized) uptime: bool, + /// log when span things happen + span_events: FmtSpan, } impl LoggerBuilder { @@ -143,7 +145,7 @@ impl LoggerBuilder { .with_thread_ids(self.display_thread_ids) .with_line_number(self.display_line_number) .with_thread_names(self.display_thread_names) - .with_span_events(FmtSpan::FULL); + .with_span_events(self.span_events); // HACK: somehow find a better solution for this // I know this is hacky, but I couldn't get it any other way. I couldn't even find a // project that could do it any other way. You can't apply one after another, because the @@ -347,6 +349,15 @@ impl LoggerBuilder { self.max_level = max_level; self } + + /// set how span events are handled + /// + /// Default: [`FmtSpan::NONE`] + #[must_use] + pub const fn span_events(mut self, span_events: FmtSpan) -> Self { + self.span_events = span_events; + self + } } impl Default for LoggerBuilder { @@ -365,11 +376,12 @@ impl Default for LoggerBuilder { pretty: false, show_time: true, uptime: false, + span_events: FmtSpan::NONE, } } } -/// ## Logger for [`pt`](libpt) +/// ## Logger for `libpt` /// /// A logger is generally a functionality that let's you write information from your library or /// application in a more structured manner than if you just wrote all information to `stdout` or