1
0

adding log framework

This commit is contained in:
EAimTY 2023-02-05 21:32:41 +09:00
parent cf189c58d6
commit e5d3c50c2d
3 changed files with 14 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"] }
once_cell = { version = "1.17.0", default-features = false, features = ["parking_lot", "std"] }
parking_lot = { version = "0.12.1", default-features = false, features = ["send_guard"] }
quinn = { version = "0.9.3", default-features = false, features = ["futures-io", "runtime-tokio", "tls-rustls"] }

View File

@ -1,5 +1,6 @@
use crate::utils::{CongestionControl, UdpRelayMode};
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::{
@ -29,6 +30,8 @@ Arguments:
pub struct Config {
pub relay: Relay,
pub local: Local,
#[serde(default = "default::log_level")]
pub log_level: LevelFilter,
}
#[derive(Deserialize)]
@ -112,6 +115,8 @@ impl Config {
}
mod default {
use log::LevelFilter;
pub mod relay {
use crate::utils::{CongestionControl, UdpRelayMode};
use std::{path::PathBuf, time::Duration};
@ -166,6 +171,10 @@ mod default {
1500
}
}
pub fn log_level() -> LevelFilter {
LevelFilter::Warn
}
}
pub fn deserialize_from_str<'de, T, D>(deserializer: D) -> Result<T, D::Error>

View File

@ -3,6 +3,7 @@ use self::{
connection::Endpoint,
socks5::Server as Socks5Server,
};
use env_logger::Builder as LoggerBuilder;
use quinn::{ConnectError, ConnectionError};
use std::{env, io::Error as IoError, process};
use thiserror::Error;
@ -28,6 +29,8 @@ async fn main() {
}
};
LoggerBuilder::new().filter_level(cfg.log_level).init();
match Endpoint::set_config(cfg.relay) {
Ok(()) => {}
Err(err) => {