From e5d3c50c2d407b639cb8b14ac83500afdb4e4532 Mon Sep 17 00:00:00 2001 From: EAimTY Date: Sun, 5 Feb 2023 21:32:41 +0900 Subject: [PATCH] adding log framework --- tuic-client/Cargo.toml | 2 ++ tuic-client/src/config.rs | 9 +++++++++ tuic-client/src/main.rs | 3 +++ 3 files changed, 14 insertions(+) diff --git a/tuic-client/Cargo.toml b/tuic-client/Cargo.toml index fc79e7a..a694194 100644 --- a/tuic-client/Cargo.toml +++ b/tuic-client/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"] } 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"] } diff --git a/tuic-client/src/config.rs b/tuic-client/src/config.rs index c44b211..6855fb3 100644 --- a/tuic-client/src/config.rs +++ b/tuic-client/src/config.rs @@ -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 diff --git a/tuic-client/src/main.rs b/tuic-client/src/main.rs index 81b7cb6..6ffdd18 100644 --- a/tuic-client/src/main.rs +++ b/tuic-client/src/main.rs @@ -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) => {