aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-08-25 19:24:25 -0700
committerBryan Newbold <bnewbold@archive.org>2020-08-25 19:24:25 -0700
commitf77729e13a26dac9d1085cf07a1eb182b1a815e0 (patch)
treed7f30c442d9621fb6a9247d9f4cbf7c467c5b667 /src
parent52c8213c0889f0ff16ff48c83121fb41bad56ba7 (diff)
downloades-public-proxy-f77729e13a26dac9d1085cf07a1eb182b1a815e0.tar.gz
es-public-proxy-f77729e13a26dac9d1085cf07a1eb182b1a815e0.zip
use log/env_logger for logging
Diffstat (limited to 'src')
-rw-r--r--src/main.rs14
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;
}