summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2021-04-29 19:23:07 -0400
committerAdam T. Carpenter <atc@53hor.net>2021-04-29 19:23:07 -0400
commit72ce821e633b57da9cba0e868940cdbd1f630f85 (patch)
tree8c41d87838f9241b2a16da3b013a03e5c0d7fa1b /src
parentf206de5d49eda1900552a4b19f01c8c6985b7903 (diff)
downloadtwinh-72ce821e633b57da9cba0e868940cdbd1f630f85.tar.xz
twinh-72ce821e633b57da9cba0e868940cdbd1f630f85.zip
fixed up config and logging
Diffstat (limited to 'src')
-rw-r--r--src/config.rs2
-rw-r--r--src/main.rs14
2 files changed, 10 insertions, 6 deletions
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(())
}