mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 12:05:05 +08:00
add support for the json format in the stream route
This commit is contained in:
parent
3b6544db6d
commit
a081da0d90
@ -38,6 +38,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
|||||||
pub enum LogMode {
|
pub enum LogMode {
|
||||||
#[default]
|
#[default]
|
||||||
Human,
|
Human,
|
||||||
|
Json,
|
||||||
Profile,
|
Profile,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +167,18 @@ fn make_layer<
|
|||||||
|
|
||||||
let fmt_layer = tracing_subscriber::fmt::layer()
|
let fmt_layer = tracing_subscriber::fmt::layer()
|
||||||
.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::CLOSE);
|
||||||
|
|
||||||
|
let stream = byte_stream(receiver, guard);
|
||||||
|
(Box::new(fmt_layer) as Box<dyn Layer<S> + 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);
|
let stream = byte_stream(receiver, guard);
|
||||||
(Box::new(fmt_layer) as Box<dyn Layer<S> + Send + Sync>, Box::pin(stream))
|
(Box::new(fmt_layer) as Box<dyn Layer<S> + Send + Sync>, Box::pin(stream))
|
||||||
|
@ -89,7 +89,7 @@ async fn logs_stream_bad_mode() {
|
|||||||
snapshot!(code, @"400 Bad Request");
|
snapshot!(code, @"400 Bad Request");
|
||||||
snapshot!(response, @r###"
|
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",
|
"code": "bad_request",
|
||||||
"type": "invalid_request",
|
"type": "invalid_request",
|
||||||
"link": "https://docs.meilisearch.com/errors#bad_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!(code, @"400 Bad Request");
|
||||||
snapshot!(response, @r###"
|
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",
|
"code": "bad_request",
|
||||||
"type": "invalid_request",
|
"type": "invalid_request",
|
||||||
"link": "https://docs.meilisearch.com/errors#bad_request"
|
"link": "https://docs.meilisearch.com/errors#bad_request"
|
||||||
|
Loading…
Reference in New Issue
Block a user