Skip to content

Commit

Permalink
fix(bin): consider env when no verbosity flag is set
Browse files Browse the repository at this point in the history
There are two ways to specify the maximum log level of `neqo-server` and
`neqo-client`. Via the `RUST_LOG` environment variable and since
mozilla#1692 via the verbosity flags (e.g. `-v`).

Previously, if no verbosity flag was provided, `INFO` was set as the maximum log
level, the `RUST_LOG` environment variable was simply ignored.

With this commit, if no flag is set, the `RUST_LOG` environment variable is
considered, and only then the `env_logger` crate default value (`ERROR`) is used.

In other words, the precedence order now is:

1. command line flags (e.g. `-v`)
2. `RUST_LOG` environment variable
3. default `ERROR` level
  • Loading branch information
mxinden committed Apr 19, 2024
1 parent 4fc4d16 commit 6ddc7d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions neqo-bin/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type Res<T> = Result<T, Error>;
#[allow(clippy::struct_excessive_bools)] // Not a good use of that lint.
pub struct Args {
#[command(flatten)]
verbose: clap_verbosity_flag::Verbosity<clap_verbosity_flag::InfoLevel>,
verbose: Option<clap_verbosity_flag::Verbosity>,

#[command(flatten)]
shared: SharedArgs,
Expand Down Expand Up @@ -180,7 +180,7 @@ impl Args {
pub fn new(requests: &[u64]) -> Self {
use std::str::FromStr;
Self {
verbose: clap_verbosity_flag::Verbosity::<clap_verbosity_flag::InfoLevel>::default(),
verbose: None,
shared: crate::SharedArgs::default(),
urls: requests
.iter()
Expand Down Expand Up @@ -485,7 +485,7 @@ fn qlog_new(args: &Args, hostname: &str, cid: &ConnectionId) -> Res<NeqoQlog> {
}

pub async fn client(mut args: Args) -> Res<()> {
neqo_common::log::init(Some(args.verbose.log_level_filter()));
neqo_common::log::init(args.verbose.as_ref().map(|v| v.log_level_filter()));
init()?;

args.update_for_tests();
Expand Down
6 changes: 3 additions & 3 deletions neqo-bin/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type Res<T> = Result<T, Error>;
#[command(author, version, about, long_about = None)]
pub struct Args {
#[command(flatten)]
verbose: clap_verbosity_flag::Verbosity<clap_verbosity_flag::InfoLevel>,
verbose: Option<clap_verbosity_flag::Verbosity>,

#[command(flatten)]
shared: SharedArgs,
Expand Down Expand Up @@ -132,7 +132,7 @@ impl Default for Args {
fn default() -> Self {
use std::str::FromStr;
Self {
verbose: clap_verbosity_flag::Verbosity::<clap_verbosity_flag::InfoLevel>::default(),
verbose: None,
shared: crate::SharedArgs::default(),
hosts: vec!["[::]:12345".to_string()],
db: PathBuf::from_str("../test-fixture/db").unwrap(),
Expand Down Expand Up @@ -587,7 +587,7 @@ enum Ready {
pub async fn server(mut args: Args) -> Res<()> {
const HQ_INTEROP: &str = "hq-interop";

neqo_common::log::init(Some(args.verbose.log_level_filter()));
neqo_common::log::init(args.verbose.as_ref().map(|v| v.log_level_filter()));
assert!(!args.key.is_empty(), "Need at least one key");

init_db(args.db.clone())?;
Expand Down

0 comments on commit 6ddc7d2

Please sign in to comment.