Skip to content

Commit 0c59b3a

Browse files
committed
feat: only debug mode can use RUST_LOG env control the log level
1 parent 07c9474 commit 0c59b3a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/cli.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
flag::{Debug, Flag},
99
};
1010
use clap::{crate_name, crate_version};
11+
use log::LevelFilter;
1112

1213
/// This should be called before calling any cli method or printing any output.
1314
pub fn reset_signal_pipe_handler() {
@@ -41,10 +42,11 @@ pub async fn main() -> Result<(), Error> {
4142
.arg_required_else_help(true)
4243
.get_matches();
4344

44-
if m.contains_id("debug") {
45+
if m.get_flag("debug") {
4546
Debug::handler()?;
4647
} else {
47-
env_logger::Builder::from_env(env_logger::Env::new().default_filter_or("info"))
48+
env_logger::Builder::new()
49+
.filter_level(LevelFilter::Info)
4850
.format_timestamp(None)
4951
.init();
5052
}

src/flag.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! -V, --version Prints version information
88
//! ```
99
use crate::err::Error;
10-
use clap::Arg;
10+
use clap::{Arg, ArgAction};
1111
use env_logger::Env;
1212

1313
/// Abstract flag trait
@@ -25,10 +25,11 @@ impl Flag for Debug {
2525
.short('d')
2626
.long("debug")
2727
.help("debug mode")
28+
.action(ArgAction::SetTrue)
2829
}
2930

3031
fn handler() -> Result<(), Error> {
31-
env_logger::Builder::from_env(Env::default().default_filter_or("leetcode")).init();
32+
env_logger::Builder::from_env(Env::default().default_filter_or("debug")).init();
3233

3334
Ok(())
3435
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy