From d7f3c13fa409ef2ee1ee78c18aae47e57383bec0 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 8 Dec 2021 11:24:25 +0100 Subject: [PATCH] Logging output improvements --- src/https.rs | 4 ++-- src/main.rs | 4 ++-- src/proxy_config.rs | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/https.rs b/src/https.rs index 2d97476..ae737d9 100644 --- a/src/https.rs +++ b/src/https.rs @@ -63,10 +63,10 @@ pub async fn serve_https( ) .await; if let Err(http_err) = http_result { - debug!("HTTP error: {}", http_err); + warn!("HTTP error: {}", http_err); } } - Err(e) => debug!("Error in TLS connection: {}", e), + Err(e) => warn!("Error in TLS connection: {}", e), } }); } diff --git a/src/main.rs b/src/main.rs index c6fd1d1..79c366b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,7 +57,7 @@ struct Opt { #[tokio::main(flavor = "multi_thread", worker_threads = 10)] async fn main() { if std::env::var("RUST_LOG").is_err() { - std::env::set_var("RUST_LOG", "tricot=debug") + std::env::set_var("RUST_LOG", "tricot=info") } pretty_env_logger::init(); @@ -81,7 +81,7 @@ async fn main() { while rx_proxy_config.changed().await.is_ok() { info!("Proxy config:"); for ent in rx_proxy_config.borrow().entries.iter() { - info!(" {:?}", ent); + info!(" {}", ent); } } } diff --git a/src/proxy_config.rs b/src/proxy_config.rs index 9092b59..2807a3b 100644 --- a/src/proxy_config.rs +++ b/src/proxy_config.rs @@ -53,6 +53,22 @@ pub struct ProxyEntry { pub calls: atomic::AtomicU64, } +impl std::fmt::Display for ProxyEntry { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{} ", self.target_addr)?; + match &self.host { + HostDescription::Hostname(h) => write!(f, "{}", h)?, + HostDescription::Pattern(p) => write!(f, "Pattern('{}')", p.as_str())?, + } + write!(f, "{} {}", self.path_prefix.as_ref().unwrap_or(&String::new()), self.priority)?; + if !self.add_headers.is_empty() { + write!(f, "+Headers: {:?}", self.add_headers)?; + } + Ok(()) + } + +} + #[derive(Debug)] pub struct ProxyConfig { pub entries: Vec,