1
0

adding log framework

This commit is contained in:
EAimTY 2023-02-05 22:30:58 +09:00
parent 8c4171ba14
commit 528d1edb7a
3 changed files with 13 additions and 0 deletions

View File

@ -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"] }

View File

@ -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<T, D::Error>

View File

@ -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) => {