From c095a6e0934cddedf570a264fc78d2210d1d9cd1 Mon Sep 17 00:00:00 2001 From: "r.4ntix" Date: Tue, 18 Oct 2022 16:12:15 +0800 Subject: [PATCH] Unified the log level configuration behavior Use RUST_LOG env first, if empty, use the --log-level-setting parameter --- ballista/executor/src/main.rs | 11 +++++------ ballista/scheduler/src/main.rs | 10 +++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ballista/executor/src/main.rs b/ballista/executor/src/main.rs index 260a72045..54e90881e 100644 --- a/ballista/executor/src/main.rs +++ b/ballista/executor/src/main.rs @@ -93,9 +93,10 @@ async fn main() -> Result<()> { let grpc_port = opt.bind_grpc_port; let log_dir = opt.log_dir; let print_thread_info = opt.print_thread_info; - let scheduler_name = format!("executor_{}_{}", bind_host, port); + let rust_log = env::var(EnvFilter::DEFAULT_ENV); + let log_filter = EnvFilter::new(rust_log.unwrap_or(special_mod_log_level)); // File layer if let Some(log_dir) = log_dir { let log_file = tracing_appender::rolling::daily(log_dir, &scheduler_name); @@ -104,18 +105,16 @@ async fn main() -> Result<()> { .with_thread_names(print_thread_info) .with_thread_ids(print_thread_info) .with_writer(log_file) - .with_env_filter(special_mod_log_level) + .with_env_filter(log_filter) .init(); } else { - //Console layer - let rust_log = env::var(EnvFilter::DEFAULT_ENV); - let std_filter = EnvFilter::new(rust_log.unwrap_or_else(|_| "INFO".to_string())); + // Console layer tracing_subscriber::fmt() .with_ansi(true) .with_thread_names(print_thread_info) .with_thread_ids(print_thread_info) .with_writer(io::stdout) - .with_env_filter(std_filter) + .with_env_filter(log_filter) .init(); } diff --git a/ballista/scheduler/src/main.rs b/ballista/scheduler/src/main.rs index f2ad64ec5..9b09db6af 100644 --- a/ballista/scheduler/src/main.rs +++ b/ballista/scheduler/src/main.rs @@ -172,6 +172,8 @@ async fn main() -> Result<()> { format!("scheduler_{}_{}_{}", namespace, external_host, port); let scheduler_name = format!("{}:{}", external_host, port); + let rust_log = env::var(EnvFilter::DEFAULT_ENV); + let log_filter = EnvFilter::new(rust_log.unwrap_or(special_mod_log_level)); // File layer if let Some(log_dir) = log_dir { let log_file = tracing_appender::rolling::daily(log_dir, &log_file_name_prefix); @@ -180,18 +182,16 @@ async fn main() -> Result<()> { .with_thread_names(print_thread_info) .with_thread_ids(print_thread_info) .with_writer(log_file) - .with_env_filter(special_mod_log_level) + .with_env_filter(log_filter) .init(); } else { - //Console layer - let rust_log = env::var(EnvFilter::DEFAULT_ENV); - let std_filter = EnvFilter::new(rust_log.unwrap_or_else(|_| "INFO".to_string())); + // Console layer tracing_subscriber::fmt() .with_ansi(true) .with_thread_names(print_thread_info) .with_thread_ids(print_thread_info) .with_writer(io::stdout) - .with_env_filter(std_filter) + .with_env_filter(log_filter) .init(); }