From a081da0d907b2f384ae33f770c03db6a8a482551 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 14 Feb 2024 15:34:39 +0100 Subject: [PATCH] add support for the json format in the stream route --- meilisearch/src/routes/logs.rs | 14 +++++++++++++- meilisearch/tests/logs/error.rs | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/meilisearch/src/routes/logs.rs b/meilisearch/src/routes/logs.rs index fe6ed21f8..57e2cbd22 100644 --- a/meilisearch/src/routes/logs.rs +++ b/meilisearch/src/routes/logs.rs @@ -38,6 +38,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) { pub enum LogMode { #[default] Human, + Json, Profile, } @@ -166,7 +167,18 @@ fn make_layer< let fmt_layer = tracing_subscriber::fmt::layer() .with_writer(move || LogWriter { sender: sender.clone() }) - .with_span_events(tracing_subscriber::fmt::format::FmtSpan::ACTIVE); + .with_span_events(tracing_subscriber::fmt::format::FmtSpan::CLOSE); + + let stream = byte_stream(receiver, guard); + (Box::new(fmt_layer) as Box + Send + Sync>, Box::pin(stream)) + } + LogMode::Json => { + let (sender, receiver) = tokio::sync::mpsc::unbounded_channel(); + + let fmt_layer = tracing_subscriber::fmt::layer() + .with_writer(move || LogWriter { sender: sender.clone() }) + .json() + .with_span_events(tracing_subscriber::fmt::format::FmtSpan::CLOSE); let stream = byte_stream(receiver, guard); (Box::new(fmt_layer) as Box + Send + Sync>, Box::pin(stream)) diff --git a/meilisearch/tests/logs/error.rs b/meilisearch/tests/logs/error.rs index 637c84add..93dcccd66 100644 --- a/meilisearch/tests/logs/error.rs +++ b/meilisearch/tests/logs/error.rs @@ -89,7 +89,7 @@ async fn logs_stream_bad_mode() { snapshot!(code, @"400 Bad Request"); snapshot!(response, @r###" { - "message": "Unknown value `tamo` at `.mode`: expected one of `human`, `profile`", + "message": "Unknown value `tamo` at `.mode`: expected one of `human`, `json`, `profile`", "code": "bad_request", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#bad_request" @@ -146,7 +146,7 @@ async fn logs_stream_bad_profile_memory() { snapshot!(code, @"400 Bad Request"); snapshot!(response, @r###" { - "message": "Unknown value `fmt` at `.mode`: expected one of `human`, `profile`", + "message": "Unknown value `fmt` at `.mode`: expected one of `human`, `json`, `profile`", "code": "bad_request", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#bad_request"