Skip to content

Commit

Permalink
Added log filtering.
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Kirilin <win10@list.ru>
  • Loading branch information
s3rius committed Dec 12, 2023
1 parent 9ef4d69 commit d988bd2
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::{
};
use axum::{
extract::{ConnectInfo, DefaultBodyLimit, MatchedPath, Request, State},
http::HeaderValue,
response::Response,
http::{HeaderValue, StatusCode},
response::{IntoResponse, Response},
Router, ServiceExt,
};
use tower::Layer;
Expand Down Expand Up @@ -54,7 +54,11 @@ async fn add_tus_header(
}

async fn healthcheck() -> impl axum::response::IntoResponse {
axum::http::StatusCode::OK
let mut response = StatusCode::OK.into_response();
response
.headers_mut()
.insert("X-NO-LOG", HeaderValue::from_static("1"));
response
}

async fn fallback() -> impl axum::response::IntoResponse {
Expand Down Expand Up @@ -143,10 +147,16 @@ pub async fn start(config: Config) -> RustusResult<()> {
)
})
.on_response(
|response: &Response, latency: Duration, span: &tracing::Span| {
move |response: &Response, latency: Duration, span: &tracing::Span| {
span.record("status", response.status().as_u16());
span.record("duration", latency.as_millis());
tracing::info!("response");
if config.no_access {
return;
}
if response.headers().contains_key("X-NO-LOG") {
return;
}
tracing::info!("access log");
},
);

Expand Down

0 comments on commit d988bd2

Please sign in to comment.