Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: debug flag #71

Merged
merged 2 commits into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub struct Config {
pub cassandra_addr: String,
pub brokermode: bool,
pub tls: bool,
pub debug: bool,
}

#[tracing::instrument(level = "trace")]
Expand All @@ -101,9 +102,14 @@ pub fn load_keys(path: &Path) -> io::Result<PrivateKeyDer<'static>> {
#[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));
};
Expand Down Expand Up @@ -147,7 +153,6 @@ pub fn get_args() -> ServerResult<Config> {
.arg(
Arg::with_name("cassandra_addr")
.value_name("CASSANDRA IPADDR")
.short("db_addr")
.long("--db_addr")
.default_value("")
.required(false)
Expand All @@ -171,6 +176,14 @@ pub fn get_args() -> ServerResult<Config> {
.help("non tls mode")
.takes_value(false),
)
.arg(
Arg::with_name("debug")
.value_name("for debug")
.long("--debug")
.required(false)
.help("log level debug")
.takes_value(false),
)
.get_matches();

let certs = load_certs(Path::new(matches.value_of("cert").unwrap()))?;
Expand All @@ -188,6 +201,7 @@ pub fn get_args() -> ServerResult<Config> {
};
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 {
Expand All @@ -196,6 +210,7 @@ pub fn get_args() -> ServerResult<Config> {
cassandra_addr: cassandra_addr.to_string(),
brokermode,
tls,
debug,
})
}

Expand Down
Loading