add our_modules() for log capture filter convenience

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-08-04 06:47:37 +00:00
parent 94b805de0b
commit 9b9a91f6ef
3 changed files with 10 additions and 3 deletions

View file

@ -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];

View file

@ -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())
}
}