summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index ab463b8..810e202 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,9 +1,16 @@
mod errors;
mod logger;
-use axum::{http::header, routing::get, Json, Router};
+use axum::{
+ http::{header, Request},
+ routing::get,
+ Json, Router,
+};
use serde::Serialize;
+use std::time::Duration;
use tower_http::sensitive_headers::SetSensitiveHeadersLayer;
+use tower_http::{classify::ServerErrorsFailureClass, trace::TraceLayer};
+use tracing::Span;
#[tokio::main]
async fn main() {
@@ -29,6 +36,17 @@ async fn create_app() -> Router {
.layer(SetSensitiveHeadersLayer::new(std::iter::once(
header::AUTHORIZATION,
)))
+ .layer(
+ TraceLayer::new_for_http()
+ .on_request(|request: &Request<_>, _span: &Span| {
+ tracing::info!("{} {}", request.method(), request.uri());
+ })
+ .on_failure(
+ |error: ServerErrorsFailureClass, latency: Duration, _span: &Span| {
+ tracing::error!("{} | {} s", error, latency.as_secs());
+ },
+ ),
+ )
}
// Example root which says hi