]> piware.de Git - learn-rust.git/blobdiff - warp-server/src/main.rs
warp-server: Add logging
[learn-rust.git] / warp-server / src / main.rs
index f4983e73ed45895573a7ca16dbf11459a4ac0348..1c75e734d32aca6e9552489815a19eb31d537e59 100644 (file)
@@ -3,6 +3,8 @@ use warp::Filter;
 
 #[tokio::main]
 async fn main() {
+    env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
+
     // GET /hello/warp => 200 OK with body "Hello, warp!"
     let hello = warp::path!("hello" / String)
         .and(warp::header::<String>("user-agent"))
@@ -23,7 +25,11 @@ async fn main() {
             })
         });
 
-    warp::serve(hello.or(echo))
+    let api = hello
+        .or(echo)
+        .with(warp::log("warp-server"));
+
+    warp::serve(api)
         .run(([127, 0, 0, 1], 3030))
         .await;
 }