Skip to content

Commit 59471a5

Browse files
committed
verbosity
1 parent b33c1f2 commit 59471a5

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/args.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ pub struct Args {
127127
/// if omitted, any OS-assignable port is used; format: 1-10,19,21
128128
#[arg(long, value_name = "ports", default_value = "")]
129129
pub udp6_port_pool: String,
130+
131+
/// Verbosity level
132+
#[arg(short, long, value_name = "level", value_enum, default_value = "info")]
133+
pub verbosity: ArgVerbosity,
130134
}
131135

132136
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum, Default)]
@@ -146,3 +150,27 @@ impl std::fmt::Display for Format {
146150
}
147151
}
148152
}
153+
154+
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
155+
pub enum ArgVerbosity {
156+
Off,
157+
Error,
158+
Warn,
159+
#[default]
160+
Info,
161+
Debug,
162+
Trace,
163+
}
164+
165+
impl std::fmt::Display for ArgVerbosity {
166+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
167+
match self {
168+
ArgVerbosity::Off => write!(f, "off"),
169+
ArgVerbosity::Error => write!(f, "error"),
170+
ArgVerbosity::Warn => write!(f, "warn"),
171+
ArgVerbosity::Info => write!(f, "info"),
172+
ArgVerbosity::Debug => write!(f, "debug"),
173+
ArgVerbosity::Trace => write!(f, "trace"),
174+
}
175+
}
176+
}

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ fn main() {
2424
use clap::Parser;
2525
let args = args::Args::parse();
2626

27-
let mut env = env_logger::Env::default().filter_or("RUST_LOG", "info");
27+
let default = args.verbosity.to_string();
28+
let mut env = env_logger::Env::default().filter_or("RUST_LOG", &default);
2829
if args.debug {
2930
env = env.filter_or("RUST_LOG", "debug");
3031
}

0 commit comments

Comments
 (0)