mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
better than before???
This commit is contained in:
parent
894c92cd5a
commit
31df954aa5
@ -88,9 +88,12 @@ fn is_empty_db(db_path: impl AsRef<Path>) -> bool {
|
|||||||
|
|
||||||
/// The handle used to update the logs at runtime. Must be accessible from the `main.rs` and the `route/logs.rs`.
|
/// The handle used to update the logs at runtime. Must be accessible from the `main.rs` and the `route/logs.rs`.
|
||||||
pub type LogRouteHandle =
|
pub type LogRouteHandle =
|
||||||
tracing_subscriber::reload::Handle<Option<LogRouteType>, tracing_subscriber::Registry>;
|
tracing_subscriber::reload::Handle<LogRouteType, tracing_subscriber::Registry>;
|
||||||
pub type LogRouteType =
|
pub type LogRouteType = tracing_subscriber::filter::Filtered<
|
||||||
Box<dyn tracing_subscriber::Layer<tracing_subscriber::Registry> + Sync + Send>;
|
Option<Box<dyn tracing_subscriber::Layer<tracing_subscriber::Registry> + Send + Sync>>,
|
||||||
|
tracing_subscriber::filter::LevelFilter,
|
||||||
|
tracing_subscriber::Registry,
|
||||||
|
>;
|
||||||
|
|
||||||
pub fn create_app(
|
pub fn create_app(
|
||||||
index_scheduler: Data<IndexScheduler>,
|
index_scheduler: Data<IndexScheduler>,
|
||||||
|
@ -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 meilisearch_auth::{generate_master_key, AuthController, MASTER_KEY_MIN_SIZE};
|
||||||
use mimalloc::MiMalloc;
|
use mimalloc::MiMalloc;
|
||||||
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
|
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;
|
use tracing_subscriber::Layer;
|
||||||
|
|
||||||
#[cfg(not(feature = "stats_alloc"))]
|
#[cfg(not(feature = "stats_alloc"))]
|
||||||
@ -27,8 +28,9 @@ static ALLOC: MiMalloc = MiMalloc;
|
|||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOC: stats_alloc::StatsAlloc<MiMalloc> = stats_alloc::StatsAlloc::new(MiMalloc);
|
static ALLOC: stats_alloc::StatsAlloc<MiMalloc> = stats_alloc::StatsAlloc::new(MiMalloc);
|
||||||
|
|
||||||
fn f<S>() -> Option<Box<dyn Layer<S> + Send + Sync>> {
|
fn default_layer<S: tracing::Subscriber>(
|
||||||
None
|
) -> tracing_subscriber::filter::Filtered<Option<Box<dyn Layer<S> + Send + Sync>>, LevelFilter, S> {
|
||||||
|
None.with_filter(tracing_subscriber::filter::LevelFilter::OFF)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// does all the setup before meilisearch is launched
|
/// does all the setup before meilisearch is launched
|
||||||
@ -44,11 +46,11 @@ fn setup(opt: &Opt) -> anyhow::Result<LogRouteHandle> {
|
|||||||
#[cfg(feature = "stats_alloc")]
|
#[cfg(feature = "stats_alloc")]
|
||||||
let (mut trace, layer) = tracing_trace::Trace::with_stats_alloc(file, &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 route_layer: tracing_subscriber::reload::Layer<_, _> = route_layer;
|
||||||
|
|
||||||
let subscriber = tracing_subscriber::registry()
|
let subscriber = tracing_subscriber::registry()
|
||||||
.with(route_layer.boxed())
|
.with(route_layer)
|
||||||
.with(
|
.with(
|
||||||
tracing_subscriber::fmt::layer()
|
tracing_subscriber::fmt::layer()
|
||||||
.with_line_number(true)
|
.with_line_number(true)
|
||||||
|
@ -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>,
|
S: tracing::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>,
|
||||||
>(
|
>(
|
||||||
opt: &GetLogs,
|
opt: &GetLogs,
|
||||||
@ -108,10 +108,7 @@ pub fn make_subscriber<
|
|||||||
let fmt_layer = tracing_subscriber::fmt::layer()
|
let fmt_layer = tracing_subscriber::fmt::layer()
|
||||||
.with_line_number(true)
|
.with_line_number(true)
|
||||||
.with_writer(move || LogWriter { sender: sender.clone() })
|
.with_writer(move || LogWriter { sender: sender.clone() })
|
||||||
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::ACTIVE)
|
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::ACTIVE);
|
||||||
.with_filter(
|
|
||||||
tracing_subscriber::filter::LevelFilter::from_str(&opt.level.to_string()).unwrap(),
|
|
||||||
);
|
|
||||||
// let subscriber = tracing_subscriber::registry().with(fmt_layer);
|
// let subscriber = tracing_subscriber::registry().with(fmt_layer);
|
||||||
|
|
||||||
Box::new(fmt_layer) as Box<dyn Layer<S> + Send + Sync>
|
Box::new(fmt_layer) as Box<dyn Layer<S> + Send + Sync>
|
||||||
@ -144,12 +141,15 @@ pub async fn get_logs(
|
|||||||
|
|
||||||
let mut was_available = false;
|
let mut was_available = false;
|
||||||
|
|
||||||
logs.modify(|layer| match layer {
|
logs.modify(|layer| match layer.inner_mut() {
|
||||||
None => {
|
None => {
|
||||||
was_available = true;
|
was_available = true;
|
||||||
// there is already someone getting logs
|
*layer.filter_mut() =
|
||||||
let subscriber = make_subscriber(&opt, sender);
|
tracing_subscriber::filter::LevelFilter::from_str(&opt.level.to_string()).unwrap();
|
||||||
*layer = Some(subscriber)
|
// there is no one getting logs
|
||||||
|
let new_layer = make_layer(&opt, sender);
|
||||||
|
|
||||||
|
*layer.inner_mut() = Some(new_layer)
|
||||||
}
|
}
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
// there is already someone getting logs
|
// there is already someone getting logs
|
||||||
|
Loading…
Reference in New Issue
Block a user