From 832becf96c3d541c5e50af26f5ddadbec26fd9e8 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 1 Nov 2022 19:03:58 +0100 Subject: [PATCH] warp-server: Add logging --- warp-server/Cargo.toml | 1 + warp-server/src/main.rs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/warp-server/Cargo.toml b/warp-server/Cargo.toml index f58a15d..600b635 100644 --- a/warp-server/Cargo.toml +++ b/warp-server/Cargo.toml @@ -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" diff --git a/warp-server/src/main.rs b/warp-server/src/main.rs index f4983e7..1c75e73 100644 --- a/warp-server/src/main.rs +++ b/warp-server/src/main.rs @@ -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::("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; } -- 2.39.5