From 9b9a91f6ef6016468461f806bdec6f7fb3dff00b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 4 Aug 2024 06:47:37 +0000 Subject: [PATCH] add our_modules() for log capture filter convenience Signed-off-by: Jason Volk --- src/admin/handler.rs | 2 +- src/core/info/mod.rs | 3 +++ src/core/log/capture/data.rs | 8 ++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/admin/handler.rs b/src/admin/handler.rs index fd4fe839..c25c380f 100644 --- a/src/admin/handler.rs +++ b/src/admin/handler.rs @@ -87,7 +87,7 @@ fn reply(mut content: RoomMessageEventContent, reply_id: Option) - // Parse and process a message from the admin room async fn process(context: &Command<'_>, command: AdminCommand, args: &[String]) -> CommandOutput { let filter: &capture::Filter = - &|data| data.level() <= Level::DEBUG && data.mod_name().starts_with("conduit") && data.scope.contains(&"admin"); + &|data| data.level() <= Level::DEBUG && data.our_modules() && data.scope.contains(&"admin"); let logs = Arc::new(Mutex::new( collect_stream(|s| markdown_table_head(s)).expect("markdown table header"), )); diff --git a/src/core/info/mod.rs b/src/core/info/mod.rs index e11a6021..e4a33b4e 100644 --- a/src/core/info/mod.rs +++ b/src/core/info/mod.rs @@ -6,3 +6,6 @@ pub mod rustc; pub mod version; pub use conduit_macros::rustc_flags_capture; + +pub const MODULE_ROOT: &str = const_str::split!(std::module_path!(), "::")[0]; +pub const CRATE_PREFIX: &str = const_str::split!(MODULE_ROOT, '_')[0]; diff --git a/src/core/log/capture/data.rs b/src/core/log/capture/data.rs index 63f09b6c..0ad7a6c2 100644 --- a/src/core/log/capture/data.rs +++ b/src/core/log/capture/data.rs @@ -2,6 +2,7 @@ use tracing::Level; use tracing_core::{span::Current, Event}; use super::{layer::Value, Layer}; +use crate::{info, utils::string::EMPTY}; pub struct Data<'a> { pub layer: &'a Layer, @@ -12,6 +13,9 @@ pub struct Data<'a> { } impl Data<'_> { + #[must_use] + pub fn our_modules(&self) -> bool { self.mod_name().starts_with(info::CRATE_PREFIX) } + #[must_use] pub fn level(&self) -> Level { *self.event.metadata().level() } @@ -19,13 +23,13 @@ impl Data<'_> { pub fn mod_name(&self) -> &str { self.event.metadata().module_path().unwrap_or_default() } #[must_use] - pub fn span_name(&self) -> &str { self.current.metadata().map_or("", |s| s.name()) } + pub fn span_name(&self) -> &str { self.current.metadata().map_or(EMPTY, |s| s.name()) } #[must_use] pub fn message(&self) -> &str { self.values .iter() .find(|(k, _)| *k == "message") - .map_or("", |(_, v)| v.as_str()) + .map_or(EMPTY, |(_, v)| v.as_str()) } }