]> piware.de Git - learn-rust.git/commitdiff
warp-server: Add logging
authorMartin Pitt <martin@piware.de>
Tue, 1 Nov 2022 18:03:58 +0000 (19:03 +0100)
committerMartin Pitt <martin@piware.de>
Tue, 1 Nov 2022 18:03:58 +0000 (19:03 +0100)
warp-server/Cargo.toml
warp-server/src/main.rs

index f58a15d33ab93d61a4cbf36372c4d7dda3165dbb..600b635b28f0f9b164ed3be25544a7b757415f89 100644 (file)
@@ -8,4 +8,5 @@ edition = "2021"
 [dependencies]
 futures-util = { version = "0.3", default-features = false, features = ["sink"] }
 tokio = { version = "1", features = ["full"] }
+env_logger = "0.9"
 warp = "0.3"
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;
 }