diff --git a/meilisearch/src/lib.rs b/meilisearch/src/lib.rs index fb2874472..435a6518b 100644 --- a/meilisearch/src/lib.rs +++ b/meilisearch/src/lib.rs @@ -88,9 +88,12 @@ fn is_empty_db(db_path: impl AsRef) -> bool { /// The handle used to update the logs at runtime. Must be accessible from the `main.rs` and the `route/logs.rs`. pub type LogRouteHandle = - tracing_subscriber::reload::Handle, tracing_subscriber::Registry>; -pub type LogRouteType = - Box + Sync + Send>; + tracing_subscriber::reload::Handle; +pub type LogRouteType = tracing_subscriber::filter::Filtered< + Option + Send + Sync>>, + tracing_subscriber::filter::LevelFilter, + tracing_subscriber::Registry, +>; pub fn create_app( index_scheduler: Data, diff --git a/meilisearch/src/main.rs b/meilisearch/src/main.rs index 5750e222d..23e1aab5a 100644 --- a/meilisearch/src/main.rs +++ b/meilisearch/src/main.rs @@ -16,7 +16,8 @@ use meilisearch::{analytics, create_app, prototype_name, setup_meilisearch, LogR use meilisearch_auth::{generate_master_key, AuthController, MASTER_KEY_MIN_SIZE}; use mimalloc::MiMalloc; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; -use tracing_subscriber::layer::SubscriberExt as _; +use tracing::level_filters::LevelFilter; +use tracing_subscriber::layer::{Filter, SubscriberExt as _}; use tracing_subscriber::Layer; #[cfg(not(feature = "stats_alloc"))] @@ -27,8 +28,9 @@ static ALLOC: MiMalloc = MiMalloc; #[global_allocator] static ALLOC: stats_alloc::StatsAlloc = stats_alloc::StatsAlloc::new(MiMalloc); -fn f() -> Option + Send + Sync>> { - None +fn default_layer( +) -> tracing_subscriber::filter::Filtered + Send + Sync>>, LevelFilter, S> { + None.with_filter(tracing_subscriber::filter::LevelFilter::OFF) } /// does all the setup before meilisearch is launched @@ -44,11 +46,11 @@ fn setup(opt: &Opt) -> anyhow::Result { #[cfg(feature = "stats_alloc")] let (mut trace, layer) = tracing_trace::Trace::with_stats_alloc(file, &ALLOC); - let (route_layer, route_layer_handle) = tracing_subscriber::reload::Layer::new(f()); + let (route_layer, route_layer_handle) = tracing_subscriber::reload::Layer::new(default_layer()); let route_layer: tracing_subscriber::reload::Layer<_, _> = route_layer; let subscriber = tracing_subscriber::registry() - .with(route_layer.boxed()) + .with(route_layer) .with( tracing_subscriber::fmt::layer() .with_line_number(true) diff --git a/meilisearch/src/routes/logs.rs b/meilisearch/src/routes/logs.rs index e5f5ae091..411eb3663 100644 --- a/meilisearch/src/routes/logs.rs +++ b/meilisearch/src/routes/logs.rs @@ -99,7 +99,7 @@ impl futures_util::Stream for LogStreamer { } } -pub fn make_subscriber< +pub fn make_layer< S: tracing::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>, >( opt: &GetLogs, @@ -108,10 +108,7 @@ pub fn make_subscriber< let fmt_layer = tracing_subscriber::fmt::layer() .with_line_number(true) .with_writer(move || LogWriter { sender: sender.clone() }) - .with_span_events(tracing_subscriber::fmt::format::FmtSpan::ACTIVE) - .with_filter( - tracing_subscriber::filter::LevelFilter::from_str(&opt.level.to_string()).unwrap(), - ); + .with_span_events(tracing_subscriber::fmt::format::FmtSpan::ACTIVE); // let subscriber = tracing_subscriber::registry().with(fmt_layer); Box::new(fmt_layer) as Box + Send + Sync> @@ -144,12 +141,15 @@ pub async fn get_logs( let mut was_available = false; - logs.modify(|layer| match layer { + logs.modify(|layer| match layer.inner_mut() { None => { was_available = true; - // there is already someone getting logs - let subscriber = make_subscriber(&opt, sender); - *layer = Some(subscriber) + *layer.filter_mut() = + tracing_subscriber::filter::LevelFilter::from_str(&opt.level.to_string()).unwrap(); + // there is no one getting logs + let new_layer = make_layer(&opt, sender); + + *layer.inner_mut() = Some(new_layer) } Some(_) => { // there is already someone getting logs