Skip to main content

tuwunel_core/log/capture/
data.rs

1use tracing::Level;
2use tracing_core::{Event, span::Current};
3
4use super::{Layer, layer::Value};
5use crate::{info, utils::string::EMPTY};
6
7pub struct Data<'a> {
8	pub layer: &'a Layer,
9	pub event: &'a Event<'a>,
10	pub current: &'a Current,
11	pub values: &'a [Value],
12	pub scope: &'a [&'static str],
13}
14
15impl Data<'_> {
16	#[must_use]
17	pub fn our_modules(&self) -> bool { self.mod_name().starts_with(info::CRATE_PREFIX) }
18
19	#[must_use]
20	pub fn level(&self) -> Level { *self.event.metadata().level() }
21
22	#[must_use]
23	pub fn mod_name(&self) -> &str {
24		self.event
25			.metadata()
26			.module_path()
27			.unwrap_or_default()
28	}
29
30	#[must_use]
31	pub fn span_name(&self) -> &str {
32		self.current
33			.metadata()
34			.map_or(EMPTY, |s| s.name())
35	}
36
37	#[must_use]
38	pub fn message(&self) -> &str {
39		self.values
40			.iter()
41			.find(|(k, _)| *k == "message")
42			.map_or(EMPTY, |(_, v)| v.as_str())
43	}
44}