From 8551c5da0501cf8212beaadb17a14d82d885f385 Mon Sep 17 00:00:00 2001 From: heya-naohiro Date: Thu, 2 May 2024 18:41:57 +0900 Subject: [PATCH 1/2] add: debug flag --- src/lib.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ada4eb6..952ec21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,6 +84,7 @@ pub struct Config { pub cassandra_addr: String, pub brokermode: bool, pub tls: bool, + pub debug: bool, } #[tracing::instrument(level = "trace")] @@ -101,9 +102,14 @@ pub fn load_keys(path: &Path) -> io::Result> { #[tracing::instrument(level = "trace")] pub fn run(config: Config) -> ServerResult<()> { // log setting - tracing_subscriber::fmt().with_max_level(Level::INFO).init(); + if config.debug { + tracing_subscriber::fmt() + .with_max_level(Level::DEBUG) + .init(); + } else { + tracing_subscriber::fmt().with_max_level(Level::INFO).init(); + } - info!("Hello log world"); if let Err(err) = start_main(config) { return Err(Box::new(err)); }; @@ -171,6 +177,15 @@ pub fn get_args() -> ServerResult { .help("non tls mode") .takes_value(false), ) + .arg( + Arg::with_name("debug") + .value_name("for debug") + .short("d") + .long("--debug") + .required(false) + .help("log level debug") + .takes_value(false), + ) .get_matches(); let certs = load_certs(Path::new(matches.value_of("cert").unwrap()))?; @@ -188,6 +203,7 @@ pub fn get_args() -> ServerResult { }; let brokermode = !matches.is_present("non_broker"); let tls = !matches.is_present("non_tls"); + let debug = matches.is_present("debug"); let cassandra_addr = matches.value_of("cassandra_addr").unwrap(); let cassandra_addr = cassandra_addr; Ok(Config { @@ -196,6 +212,7 @@ pub fn get_args() -> ServerResult { cassandra_addr: cassandra_addr.to_string(), brokermode, tls, + debug, }) } From 805e4c514a62f1933ab199e81b33f57c1cfe743b Mon Sep 17 00:00:00 2001 From: heya-naohiro Date: Thu, 2 May 2024 18:48:18 +0900 Subject: [PATCH 2/2] fix: option --- src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 952ec21..9999304 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -153,7 +153,6 @@ pub fn get_args() -> ServerResult { .arg( Arg::with_name("cassandra_addr") .value_name("CASSANDRA IPADDR") - .short("db_addr") .long("--db_addr") .default_value("") .required(false) @@ -180,7 +179,6 @@ pub fn get_args() -> ServerResult { .arg( Arg::with_name("debug") .value_name("for debug") - .short("d") .long("--debug") .required(false) .help("log level debug")