diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 0250976..0f94a84 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,17 +4,20 @@ use std::env; use std::net::SocketAddr; use toml; +#[macro_use] +extern crate log; + use es_public_proxy::{filter_request, ProxyConfig}; async fn upstream_req( req: Request<Body>, config: ProxyConfig, ) -> Result<Response<Body>, hyper::Error> { - println!("hit: {}", req.uri()); + info!("hit: {}", req.uri()); let parsed = filter_request(req, &config).await; let resp = match parsed { Ok(upstream_req) => { - println!("sending request..."); + debug!("sending request..."); Client::new().request(upstream_req).await? } Err(other) => Response::builder() @@ -23,7 +26,7 @@ async fn upstream_req( .body(serde_json::to_string(&other.to_json()).unwrap().into()) .unwrap(), }; - println!("resp!"); + debug!("resp!"); Ok(resp) } @@ -40,7 +43,7 @@ async fn run_server(config: ProxyConfig) { Some(addr) => addr.parse().unwrap(), }; - println!("Listening on http://{}", addr); + info!("Listening on http://{}", addr); // TODO: possible to avoid cloning config on every connection? let make_svc = make_service_fn(move |_| { @@ -51,7 +54,7 @@ async fn run_server(config: ProxyConfig) { let graceful = serve_future.with_graceful_shutdown(shutdown_signal()); if let Err(e) = graceful.await { - eprintln!("server error: {}", e); + error!("server error: {}", e); } } @@ -103,5 +106,6 @@ fn load_config() -> ProxyConfig { #[tokio::main] async fn main() { let config = load_config(); + env_logger::init(); run_server(config).await; } |