diff --git a/Cargo.toml b/Cargo.toml index 19f3926..631d536 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,6 @@ serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.115" tokio = { version = "1.37.0", features = ["full"] } tower = "0.4.13" -tower-http = { version = "0.5.2", features = ["fs"]} +tower-http = { version = "0.5.2", features = ["fs", "trace"]} tracing = "0.1.40" tracing-subscriber = "0.3.18" diff --git a/src/main.rs b/src/main.rs index ae212ac..bdb0cdf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,24 +1,22 @@ mod dem; use axum::{ - extract::{Path, State}, - routing::get, - Router, + extract::{Path, State}, http::Request, routing::get, Router }; use axum_macros::debug_handler; use std::env; -use tower_http::services::ServeDir; +use tower_http::{services::ServeDir, trace::{self, DefaultMakeSpan}}; use dem::DatasetRepository; -use tracing::info; +use tracing::{info, Level, Span}; +use tower_http::trace::TraceLayer; const DEFAULT_DATA_DIR: &str = "/data"; const DEFAULT_PORT: &str = "3000"; -//#[tokio::main(flavor = "current_thread")] #[tokio::main] async fn main() { // initialize tracing @@ -30,11 +28,15 @@ async fn main() { let serve_dir = ServeDir::new("assets"); - // build our application with a route let app = Router::new() .route("/elevation/:lat/:lon", get(get_elevation)) .nest_service("/", serve_dir) - .with_state(cache); + .with_state(cache) + .layer( + TraceLayer::new_for_http() + .make_span_with(trace::DefaultMakeSpan::new().level(Level::INFO)) + .on_response(trace::DefaultOnResponse::new().level(Level::INFO)), + ); let host = format!("[::]:{}", config.port); info!("Will start server on {host}"); @@ -61,4 +63,4 @@ fn load_config() -> Result { struct Config { basedir: String, port: String, -} \ No newline at end of file +}