use std::sync::Arc;
use std::time::Instant;
use log::info;
use crate::{DynHandler, Request, Response};
pub type Middleware = Arc<dyn Fn(DynHandler) -> DynHandler + Send + Sync>;
pub fn logging(next: DynHandler) -> DynHandler {
Arc::new(move |req: Request| -> Response {
let (method, path) = (req.method().to_string(), req.full_path().to_string());
info!("{} {}", method, path);
let start = Instant::now();
let res = next(req);
let duration = start.elapsed();
info!("{} {} finished in {:?}", method, path, duration);
res
})
}