mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-09-11 16:03:02 +02:00
tracing capture interface
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
1bb4021b90
commit
aa34021b27
15 changed files with 284 additions and 27 deletions
50
src/core/log/capture/mod.rs
Normal file
50
src/core/log/capture/mod.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
pub mod data;
|
||||
mod guard;
|
||||
pub mod layer;
|
||||
pub mod state;
|
||||
pub mod util;
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
pub use data::Data;
|
||||
use guard::Guard;
|
||||
pub use layer::{Layer, Value};
|
||||
pub use state::State;
|
||||
pub use util::to_html;
|
||||
|
||||
pub type Filter = dyn Fn(Data<'_>) -> bool + Send + Sync + 'static;
|
||||
pub type Closure = dyn FnMut(Data<'_>) + Send + Sync + 'static;
|
||||
|
||||
/// Capture instance state.
|
||||
pub struct Capture {
|
||||
state: Arc<State>,
|
||||
filter: Option<Box<Filter>>,
|
||||
closure: Mutex<Box<Closure>>,
|
||||
}
|
||||
|
||||
impl Capture {
|
||||
/// Construct a new capture instance. Capture does not start until the Guard
|
||||
/// is in scope.
|
||||
#[must_use]
|
||||
pub fn new<F, C>(state: &Arc<State>, filter: Option<F>, closure: C) -> Arc<Self>
|
||||
where
|
||||
F: Fn(Data<'_>) -> bool + Send + Sync + 'static,
|
||||
C: FnMut(Data<'_>) + Send + Sync + 'static,
|
||||
{
|
||||
Arc::new(Self {
|
||||
state: state.clone(),
|
||||
filter: filter.map(|p| -> Box<Filter> { Box::new(p) }),
|
||||
closure: Mutex::new(Box::new(closure)),
|
||||
})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn start(self: &Arc<Self>) -> Guard {
|
||||
self.state.add(self);
|
||||
Guard {
|
||||
capture: self.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop(self: &Arc<Self>) { self.state.del(self); }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue