From 89257c8fe5be5a7b4b0ed9636f186c8f57b7d862 Mon Sep 17 00:00:00 2001 From: tetta maeda Date: Fri, 5 Apr 2024 15:32:51 +0900 Subject: [PATCH 1/2] =?UTF-8?q?CLI=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=81=A7=E3=83=AD=E3=82=B0=E3=83=AC=E3=83=99=E3=83=AB=E3=82=92?= =?UTF-8?q?=E6=8C=87=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 113 +++++++++++++++++++++++++++++++++ moqt-server-sample/Cargo.toml | 1 + moqt-server-sample/src/main.rs | 10 +++ moqt-server/src/lib.rs | 28 ++++++-- 4 files changed, 148 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5a962ba0..11e2ba00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,54 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" version = "1.0.81" @@ -142,6 +190,52 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -335,6 +429,12 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -491,6 +591,7 @@ name = "moqt-server-sample" version = "0.1.0" dependencies = [ "anyhow", + "clap", "moqt-server", "tokio", ] @@ -1053,6 +1154,12 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "syn" version = "2.0.58" @@ -1301,6 +1408,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "valuable" version = "0.1.0" diff --git a/moqt-server-sample/Cargo.toml b/moqt-server-sample/Cargo.toml index bcdb6ecf..e0352cf7 100644 --- a/moqt-server-sample/Cargo.toml +++ b/moqt-server-sample/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" anyhow = { version = "1.0.75", features = ["backtrace"] } moqt-server = {path = "../moqt-server"} tokio = { version = "1.32.0", features = ["rt-multi-thread"] } +clap = { version = "4.5.4", features = ["derive"] } [features] diff --git a/moqt-server-sample/src/main.rs b/moqt-server-sample/src/main.rs index 268af749..b02d9750 100644 --- a/moqt-server-sample/src/main.rs +++ b/moqt-server-sample/src/main.rs @@ -1,12 +1,22 @@ use anyhow::{Ok, Result}; +use clap::Parser; use moqt_server::{constants::UnderlayType, MOQTConfig, MOQT}; +#[derive(Debug, Parser)] +struct Arg { + #[arg(short = 'l', long = "log", help = "Log Level", default_value = "DEBUG")] + log_level: String, +} + #[tokio::main] async fn main() -> Result<()> { + let args = Arg::parse(); + let mut config = MOQTConfig::new(); config.underlay = UnderlayType::WebTransport; config.key_path = "./moqt-server-sample/keys/key.pem".to_string(); config.cert_path = "./moqt-server-sample/keys/cert.pem".to_string(); + config.log_level = args.log_level.to_string(); // config.auth_callback = Some(|track_name: String, auth_payload: String, auth_callback_type: AuthCallbackType| {Ok(())}); diff --git a/moqt-server/src/lib.rs b/moqt-server/src/lib.rs index 8db5f568..708f9472 100644 --- a/moqt-server/src/lib.rs +++ b/moqt-server/src/lib.rs @@ -39,6 +39,7 @@ pub struct MOQTConfig { pub keep_alive_interval_sec: u64, pub underlay: UnderlayType, pub auth_callback: Option, + pub log_level: String, } impl Default for MOQTConfig { @@ -57,6 +58,7 @@ impl MOQTConfig { keep_alive_interval_sec: 3, underlay: UnderlayType::Both, auth_callback: None, + log_level: "DEBUG".to_string(), } } } @@ -68,6 +70,7 @@ pub struct MOQT { keep_alive_interval_sec: u64, underlay: UnderlayType, // auth_callback: Option, + log_level: String, } impl MOQT { @@ -79,10 +82,11 @@ impl MOQT { keep_alive_interval_sec: config.keep_alive_interval_sec, underlay: config.underlay, // auth_callback: config.auth_callback, + log_level: config.log_level, } } pub async fn start(&self) -> Result<()> { - init_logging(); + init_logging(self.log_level.to_string()); // For buffer management for each stream let (buffer_tx, mut buffer_rx) = mpsc::channel::(1024); @@ -337,10 +341,24 @@ async fn handle_stream( Ok::<()>(()) } -// TODO: LogLevelを設定できるようにする -fn init_logging() { +fn init_logging(log_level: String) { + let level_filter: LevelFilter = match log_level.to_uppercase().as_str() { + "OFF" => LevelFilter::OFF, + "TRACE" => LevelFilter::TRACE, + "DEBUG" => LevelFilter::DEBUG, + "INFO" => LevelFilter::INFO, + "WARN" => LevelFilter::WARN, + "ERROR" => LevelFilter::ERROR, + _ => { + panic!( + "Invalid log level: '{}'.\n Valid log levels: [OFF, TRACE, DEBUG, INFO, WARN, ERROR]", + log_level + ); + } + }; + let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::DEBUG.into()) + .with_default_directive(level_filter.into()) .from_env_lossy(); tracing_subscriber::fmt() @@ -348,4 +366,6 @@ fn init_logging() { .with_level(true) .with_env_filter(env_filter) .init(); + + tracing::info!("Logging initialized. (Level: {})", log_level); } From 639216f9ab2ec607cab2f81988a175458e66d109 Mon Sep 17 00:00:00 2001 From: tetta maeda Date: Fri, 5 Apr 2024 15:38:03 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=83=AD=E3=82=B0=E3=83=AC=E3=83=99?= =?UTF-8?q?=E3=83=AB=E8=A8=AD=E5=AE=9A=E6=96=B9=E6=B3=95=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E8=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index bcc25ab8..ceb766cb 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,11 @@ openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -out cert.pem -subj '/ - `cargo run -p moqt-server-sample` +#### ログレベルの指定 + +- `cargo run -p moqt-server-sample -- -log ` + - Default setting is `DEBUG` + ### moqt-client-sample の実行 - `cd js && npm install && npm run dev`