fix: Make default output of delorean less chatty
parent
13309e10f2
commit
d1e334f3fe
39
src/main.rs
39
src/main.rs
|
@ -102,13 +102,13 @@ Examples:
|
|||
),
|
||||
)
|
||||
.subcommand(SubCommand::with_name("server").about("Runs in server mode (default)"))
|
||||
.arg(Arg::with_name("verbose").short("v").long("verbose").help(
|
||||
"Enables verbose logging. You can also set log level via \
|
||||
.arg(Arg::with_name("verbose").short("v").long("verbose").multiple(true).help(
|
||||
"Enables verbose logging (use 'vv' for even more verbosity). You can also set log level via \
|
||||
the environment variable RUST_LOG=<value>",
|
||||
))
|
||||
.get_matches();
|
||||
|
||||
setup_logging(matches.is_present("verbose"));
|
||||
setup_logging(matches.occurrences_of("verbose"));
|
||||
|
||||
match matches.subcommand() {
|
||||
("convert", Some(sub_matches)) => {
|
||||
|
@ -161,32 +161,35 @@ Examples:
|
|||
/// some especially noisy low level libraries
|
||||
const DEFAULT_DEBUG_LOG_LEVEL: &str = "debug,h2=info";
|
||||
|
||||
// Default log level is info level for all components
|
||||
const DEFAULT_LOG_LEVEL: &str = "info";
|
||||
// Default verbose log level is info level for all components
|
||||
const DEFAULT_VERBOSE_LOG_LEVEL: &str = "info";
|
||||
|
||||
// Default log level is warn level for all components
|
||||
const DEFAULT_LOG_LEVEL: &str = "warn";
|
||||
|
||||
/// Configures logging in the following precedence:
|
||||
///
|
||||
/// 1. If RUST_LOG environment variable is set, use that value
|
||||
/// 2. if `verbose_requested`, use DEFAULT_DEBUG_LOG_LEVEL
|
||||
/// 3. otherwise, use DEFAULT_LOG_LEVEL
|
||||
fn setup_logging(verbose_requested: bool) {
|
||||
/// 2. if `-vv` (multiple instances of verbose), use DEFAULT_DEBUG_LOG_LEVEL
|
||||
/// 2. if `-v` (single instances of verbose), use DEFAULT_VERBOSE_LOG_LEVEL
|
||||
/// 3. Otherwise use DEFAULT_LOG_LEVEL
|
||||
fn setup_logging(num_verbose: u64) {
|
||||
let rust_log_env = std::env::var("RUST_LOG");
|
||||
|
||||
if verbose_requested {
|
||||
match rust_log_env {
|
||||
Ok(lvl) => {
|
||||
match rust_log_env {
|
||||
Ok(lvl) => {
|
||||
if num_verbose > 0 {
|
||||
eprintln!(
|
||||
"WARNING: Using RUST_LOG='{}' environment, ignoring request for -v",
|
||||
"WARNING: Using RUST_LOG='{}' environment, ignoring -v command line",
|
||||
lvl
|
||||
);
|
||||
}
|
||||
Err(_) => std::env::set_var("RUST_LOG", DEFAULT_DEBUG_LOG_LEVEL),
|
||||
}
|
||||
} else {
|
||||
match rust_log_env {
|
||||
Ok(_) => {}
|
||||
Err(_) => std::env::set_var("RUST_LOG", DEFAULT_LOG_LEVEL),
|
||||
}
|
||||
Err(_) => match num_verbose {
|
||||
0 => std::env::set_var("RUST_LOG", DEFAULT_LOG_LEVEL),
|
||||
1 => std::env::set_var("RUST_LOG", DEFAULT_VERBOSE_LOG_LEVEL),
|
||||
_ => std::env::set_var("RUST_LOG", DEFAULT_DEBUG_LOG_LEVEL),
|
||||
},
|
||||
}
|
||||
|
||||
env_logger::init();
|
||||
|
|
|
@ -32,6 +32,7 @@ fn validate_parquet_file(p: &Path) {
|
|||
fn convert_bad_input_filename() {
|
||||
let mut cmd = Command::cargo_bin("delorean").unwrap();
|
||||
let assert = cmd
|
||||
.arg("-v")
|
||||
.arg("convert")
|
||||
.arg("non_existent_input.lp")
|
||||
.arg("non_existent_output")
|
||||
|
@ -50,6 +51,7 @@ fn convert_bad_input_filename() {
|
|||
fn convert_bad_compression_level() {
|
||||
let mut cmd = Command::cargo_bin("delorean").unwrap();
|
||||
let assert = cmd
|
||||
.arg("-v")
|
||||
.arg("convert")
|
||||
.arg("--compression-level")
|
||||
.arg("maxxx")
|
||||
|
@ -75,6 +77,7 @@ fn convert_line_protocol_good_input_filename() {
|
|||
let parquet_filename_string = parquet_path.to_string_lossy().to_string();
|
||||
|
||||
let assert = cmd
|
||||
.arg("-v")
|
||||
.arg("convert")
|
||||
.arg("--compression-level")
|
||||
.arg("compatibility")
|
||||
|
@ -163,6 +166,7 @@ fn convert_multiple_measurements() {
|
|||
let parquet_output_dir_path = parquet_output_path.path().to_string_lossy().to_string();
|
||||
|
||||
let assert = cmd
|
||||
.arg("-v")
|
||||
.arg("convert")
|
||||
.arg("tests/fixtures/lineproto/air_and_water.lp")
|
||||
.arg(&parquet_output_dir_path)
|
||||
|
|
Loading…
Reference in New Issue