Skip to content

Commit 8d83fa2

Browse files
authored
Unified the log level configuration behavior (#386)
Use RUST_LOG env first, if empty, use the --log-level-setting parameter
1 parent f4e6a55 commit 8d83fa2

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

ballista/executor/src/main.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ async fn main() -> Result<()> {
9393
let grpc_port = opt.bind_grpc_port;
9494
let log_dir = opt.log_dir;
9595
let print_thread_info = opt.print_thread_info;
96-
9796
let scheduler_name = format!("executor_{}_{}", bind_host, port);
9897

98+
let rust_log = env::var(EnvFilter::DEFAULT_ENV);
99+
let log_filter = EnvFilter::new(rust_log.unwrap_or(special_mod_log_level));
99100
// File layer
100101
if let Some(log_dir) = log_dir {
101102
let log_file = tracing_appender::rolling::daily(log_dir, &scheduler_name);
@@ -104,18 +105,16 @@ async fn main() -> Result<()> {
104105
.with_thread_names(print_thread_info)
105106
.with_thread_ids(print_thread_info)
106107
.with_writer(log_file)
107-
.with_env_filter(special_mod_log_level)
108+
.with_env_filter(log_filter)
108109
.init();
109110
} else {
110-
//Console layer
111-
let rust_log = env::var(EnvFilter::DEFAULT_ENV);
112-
let std_filter = EnvFilter::new(rust_log.unwrap_or_else(|_| "INFO".to_string()));
111+
// Console layer
113112
tracing_subscriber::fmt()
114113
.with_ansi(true)
115114
.with_thread_names(print_thread_info)
116115
.with_thread_ids(print_thread_info)
117116
.with_writer(io::stdout)
118-
.with_env_filter(std_filter)
117+
.with_env_filter(log_filter)
119118
.init();
120119
}
121120

ballista/scheduler/src/main.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ async fn main() -> Result<()> {
172172
format!("scheduler_{}_{}_{}", namespace, external_host, port);
173173
let scheduler_name = format!("{}:{}", external_host, port);
174174

175+
let rust_log = env::var(EnvFilter::DEFAULT_ENV);
176+
let log_filter = EnvFilter::new(rust_log.unwrap_or(special_mod_log_level));
175177
// File layer
176178
if let Some(log_dir) = log_dir {
177179
let log_file = tracing_appender::rolling::daily(log_dir, &log_file_name_prefix);
@@ -180,18 +182,16 @@ async fn main() -> Result<()> {
180182
.with_thread_names(print_thread_info)
181183
.with_thread_ids(print_thread_info)
182184
.with_writer(log_file)
183-
.with_env_filter(special_mod_log_level)
185+
.with_env_filter(log_filter)
184186
.init();
185187
} else {
186-
//Console layer
187-
let rust_log = env::var(EnvFilter::DEFAULT_ENV);
188-
let std_filter = EnvFilter::new(rust_log.unwrap_or_else(|_| "INFO".to_string()));
188+
// Console layer
189189
tracing_subscriber::fmt()
190190
.with_ansi(true)
191191
.with_thread_names(print_thread_info)
192192
.with_thread_ids(print_thread_info)
193193
.with_writer(io::stdout)
194-
.with_env_filter(std_filter)
194+
.with_env_filter(log_filter)
195195
.init();
196196
}
197197

0 commit comments

Comments
 (0)