1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
mod layer;
use crate::common::ingest;
pub use crate::options::Options;
use crate::InitError;
pub use ingest::{ModalityIngestTaskHandle, TimelineId};
pub use layer::ModalityLayer;
use anyhow::Context as _;
use tracing_core::Dispatch;
pub struct TracingModality {
ingest_handle: ModalityIngestTaskHandle,
}
impl TracingModality {
pub async fn init() -> Result<Self, InitError> {
Self::init_with_options(Default::default()).await
}
pub async fn init_with_options(opts: Options) -> Result<Self, InitError> {
let (layer, ingest_handle) = ModalityLayer::init_with_options(opts)
.await
.context("initialize ModalityLayer")?;
let disp = Dispatch::new(layer.into_subscriber());
tracing::dispatcher::set_global_default(disp).unwrap();
Ok(Self { ingest_handle })
}
pub async fn finish(self) {
self.ingest_handle.finish().await;
}
}