33 lines
1.0 KiB
Rust
33 lines
1.0 KiB
Rust
use tokio::task::JoinHandle;
|
|
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
|
|
use tracing_subscriber::{fmt::MakeWriter, layer::SubscriberExt, util::SubscriberInitExt};
|
|
|
|
pub fn init_subscriber<Sink>(sink: Sink)
|
|
where
|
|
Sink: for<'a> MakeWriter<'a> + Send + Sync + 'static,
|
|
{
|
|
let formatting_layer = BunyanFormattingLayer::new(env!("CARGO_CRATE_NAME").into(), sink);
|
|
tracing_subscriber::registry()
|
|
.with(
|
|
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
|
|
format!(
|
|
"{}=debug,tower_http=debug,axum::rejection=trace",
|
|
env!("CARGO_CRATE_NAME")
|
|
)
|
|
.into()
|
|
}),
|
|
)
|
|
.with(JsonStorageLayer)
|
|
.with(formatting_layer)
|
|
.init();
|
|
}
|
|
|
|
pub fn spawn_blocking_with_tracing<F, R>(f: F) -> JoinHandle<R>
|
|
where
|
|
F: FnOnce() -> R + Send + 'static,
|
|
R: Send + 'static,
|
|
{
|
|
let current_span = tracing::Span::current();
|
|
tokio::task::spawn_blocking(move || current_span.in_scope(f))
|
|
}
|