From f77729e13a26dac9d1085cf07a1eb182b1a815e0 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 25 Aug 2020 19:24:25 -0700 Subject: use log/env_logger for logging --- src/main.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') 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, config: ProxyConfig, ) -> Result, 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; } -- cgit v1.2.3