Skip to content

Commit 9b7c1d3

Browse files
committed
Add response logging with status code and time spent
So we can diagnose issues faster, in particular regarding client closed connection (no logging) and time spent.
1 parent 92fe2ec commit 9b7c1d3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use anyhow::Context as _;
44
use axum::body::Body;
55
use axum::error_handling::HandleErrorLayer;
66
use axum::http::HeaderName;
7-
use axum::response::Html;
7+
use axum::response::{Html, Response};
88
use axum::routing::{get, post};
99
use axum::{BoxError, Router};
1010
use hyper::{Request, StatusCode};
@@ -132,6 +132,9 @@ async fn run_server(addr: SocketAddr) -> anyhow::Result<()> {
132132
})
133133
.on_request(|request: &Request<Body>, _span: &tracing::Span| {
134134
tracing::info!(?request);
135+
})
136+
.on_response(|response: &Response<_>, dur, _span: &tracing::Span| {
137+
tracing::info!("response={} in {dur:?}", response.status());
135138
}),
136139
)
137140
.layer(PropagateRequestIdLayer::new(X_REQUEST_ID))

0 commit comments

Comments
 (0)