diff --git a/tuic-server/Cargo.toml b/tuic-server/Cargo.toml index 6b1dc5e..ddb3005 100644 --- a/tuic-server/Cargo.toml +++ b/tuic-server/Cargo.toml @@ -6,7 +6,9 @@ edition = "2021" [dependencies] bytes = { version = "1.4.0", default-features = false, features = ["std"] } crossbeam-utils = { version = "0.8.14", default-features = false, features = ["std"] } +env_logger = { version = "0.10.0", default-features = false, features = ["humantime"] } lexopt = { version = "0.3.0", default-features = false } +log = { version = "0.4.17", default-features = false, features = ["serde", "std"] } parking_lot = { version = "0.12.1", default-features = false } quinn = { version = "0.9.3", default-features = false, features = ["futures-io", "runtime-tokio", "tls-rustls"] } register-count = { version = "0.1.0", default-features = false, features = ["std"] } diff --git a/tuic-server/src/config.rs b/tuic-server/src/config.rs index d08c1a2..e409ffe 100644 --- a/tuic-server/src/config.rs +++ b/tuic-server/src/config.rs @@ -1,5 +1,6 @@ use crate::utils::CongestionControl; use lexopt::{Arg, Error as ArgumentError, Parser}; +use log::LevelFilter; use serde::{de::Error as DeError, Deserialize, Deserializer}; use serde_json::Error as SerdeError; use std::{ @@ -48,6 +49,8 @@ pub struct Config { pub gc_interval: Duration, #[serde(default = "default::gc_lifetime")] pub gc_lifetime: Duration, + #[serde(default = "default::log_level")] + pub log_level: LevelFilter, } impl Config { @@ -83,6 +86,7 @@ impl Config { mod default { use crate::utils::CongestionControl; + use log::LevelFilter; use std::time::Duration; pub fn congestion_control() -> CongestionControl { @@ -120,6 +124,10 @@ mod default { pub fn gc_lifetime() -> Duration { Duration::from_secs(15) } + + pub fn log_level() -> LevelFilter { + LevelFilter::Warn + } } pub fn deserialize_from_str<'de, T, D>(deserializer: D) -> Result diff --git a/tuic-server/src/main.rs b/tuic-server/src/main.rs index 2021912..9e689a3 100644 --- a/tuic-server/src/main.rs +++ b/tuic-server/src/main.rs @@ -2,6 +2,7 @@ use self::{ config::{Config, ConfigError}, server::Server, }; +use env_logger::Builder as LoggerBuilder; use quinn::ConnectionError; use rustls::Error as RustlsError; use std::{env, io::Error as IoError, net::SocketAddr, process}; @@ -28,6 +29,8 @@ async fn main() { } }; + LoggerBuilder::new().filter_level(cfg.log_level).init(); + match Server::init(cfg) { Ok(server) => server.start().await, Err(err) => {