From 72ce821e633b57da9cba0e868940cdbd1f630f85 Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Thu, 29 Apr 2021 19:23:07 -0400 Subject: fixed up config and logging --- src/config.rs | 2 +- src/main.rs | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 4dd4433..c4396d4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -32,7 +32,7 @@ pub struct Config { parse(from_occurrences), help = "Increases log level" )] - pub verbose: u8, + pub verbose: usize, #[structopt( long, diff --git a/src/main.rs b/src/main.rs index c6a1110..a17e2b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,7 @@ use hyper::{ service::{make_service_fn, service_fn}, Server, }; -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use structopt::StructOpt; +use log::LevelFilter; #[macro_use] extern crate lazy_static; @@ -19,7 +18,13 @@ mod templates; #[tokio::main] async fn main() -> Result<(), TwinHError> { - //env_logger::try_init_from_env; + // configure logger + let level = match config::INSTANCE.verbose { + 1 => LevelFilter::Info, + 2 => LevelFilter::Debug, + _ => LevelFilter::Warn, + }; + env_logger::builder().filter_level(level).init(); // create HTTP listener let make_svc = @@ -29,9 +34,8 @@ async fn main() -> Result<(), TwinHError> { let server = Server::bind(&config::INSTANCE.bind_addr.into()).serve(make_svc); let graceful = server.with_graceful_shutdown(shutdown_signal()); - // start and run + // start and wait for shutdown graceful.await?; - Ok(()) } -- cgit v1.2.3