use axum::{extract::Request, middleware::Next, response::Response};
use std::time::Instant;
pub async fn logging_middleware(req: Request, next: Next) -> Response {
let start = Instant::now();
let method = req.method().clone();
let uri = req.uri().clone();
let path = uri.path().to_string();
let query = uri.query().map(|q| q.to_string());
tracing::debug!(
method = %method,
path = %path,
query = ?query,
"REQ"
);
let response = next.run(req).await;
let duration = start.elapsed();
let status = response.status();
tracing::debug!(
method = %method,
path = %path,
status = %status,
duration = ?duration,
"RES"
);
response
}