This is an automated email from the ASF dual-hosted git repository.
agrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-ballista.git
The following commit(s) were added to refs/heads/master by this push:
new 93916c37 [MINOR] Add log info in stdout (#187)
93916c37 is described below
commit 93916c37a59b20146119fd577b67aaf89b12f4bc
Author: Yang Jiang <[email protected]>
AuthorDate: Thu Sep 8 11:00:23 2022 +0800
[MINOR] Add log info in stdout (#187)
* add log info in stdout
* make log print to stdout deafult
---
ballista/rust/executor/executor_config_spec.toml | 1 -
ballista/rust/executor/src/main.rs | 34 ++++++++++++++------
ballista/rust/scheduler/scheduler_config_spec.toml | 1 -
ballista/rust/scheduler/src/main.rs | 36 +++++++++++++++-------
4 files changed, 50 insertions(+), 22 deletions(-)
diff --git a/ballista/rust/executor/executor_config_spec.toml
b/ballista/rust/executor/executor_config_spec.toml
index e34c27fa..bbad37a8 100644
--- a/ballista/rust/executor/executor_config_spec.toml
+++ b/ballista/rust/executor/executor_config_spec.toml
@@ -107,7 +107,6 @@ default = "std::string::String::from(\"\")"
name = "log_dir"
type = "String"
doc = "Log dir: a path to save log. This will create a new storage directory
at the specified path if it does not already exist."
-default = "std::string::String::from(\"./logs\")"
[[param]]
name = "print_thread_info"
diff --git a/ballista/rust/executor/src/main.rs
b/ballista/rust/executor/src/main.rs
index ee7dfdd1..010aaae9 100644
--- a/ballista/rust/executor/src/main.rs
+++ b/ballista/rust/executor/src/main.rs
@@ -21,6 +21,7 @@ use chrono::{DateTime, Duration, Utc};
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration as Core_Duration;
+use std::{env, io};
use anyhow::{Context, Result};
use arrow_flight::flight_service_server::FlightServiceServer;
@@ -54,6 +55,7 @@ use futures::stream::FuturesUnordered;
use futures::StreamExt;
use tokio::sync::mpsc;
use tokio::task::JoinHandle;
+use tracing_subscriber::EnvFilter;
#[macro_use]
extern crate configure_me;
@@ -90,15 +92,29 @@ async fn main() -> Result<()> {
let print_thread_info = opt.print_thread_info;
let scheduler_name = format!("executor_{}_{}", bind_host, port);
- let log_file = tracing_appender::rolling::daily(log_dir, &scheduler_name);
-
- tracing_subscriber::fmt()
- .with_ansi(true)
- .with_thread_names(print_thread_info)
- .with_thread_ids(print_thread_info)
- .with_writer(log_file)
- .with_env_filter(special_mod_log_level)
- .init();
+
+ // File layer
+ if let Some(log_dir) = log_dir {
+ let log_file = tracing_appender::rolling::daily(log_dir,
&scheduler_name);
+ tracing_subscriber::fmt()
+ .with_ansi(true)
+ .with_thread_names(print_thread_info)
+ .with_thread_ids(print_thread_info)
+ .with_writer(log_file)
+ .with_env_filter(special_mod_log_level)
+ .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()));
+ 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)
+ .init();
+ }
let addr = format!("{}:{}", bind_host, port);
let addr = addr
diff --git a/ballista/rust/scheduler/scheduler_config_spec.toml
b/ballista/rust/scheduler/scheduler_config_spec.toml
index 1f89562d..c57225e9 100644
--- a/ballista/rust/scheduler/scheduler_config_spec.toml
+++ b/ballista/rust/scheduler/scheduler_config_spec.toml
@@ -88,7 +88,6 @@ default = "std::string::String::from(\"\")"
name = "log_dir"
type = "String"
doc = "Log dir: a path to save log. This will create a new storage directory
at the specified path if it does not already exist."
-default = "std::string::String::from(\"./logs\")"
[[param]]
name = "print_thread_info"
diff --git a/ballista/rust/scheduler/src/main.rs
b/ballista/rust/scheduler/src/main.rs
index c28ec98a..be8acfc7 100644
--- a/ballista/rust/scheduler/src/main.rs
+++ b/ballista/rust/scheduler/src/main.rs
@@ -24,7 +24,7 @@ use
ballista_scheduler::scheduler_server::externalscaler::external_scaler_server
use futures::future::{self, Either, TryFutureExt};
use hyper::{server::conn::AddrStream, service::make_service_fn, Server};
use std::convert::Infallible;
-use std::{net::SocketAddr, sync::Arc};
+use std::{env, io, net::SocketAddr, sync::Arc};
use tonic::transport::server::Connected;
use tower::Service;
@@ -65,6 +65,7 @@ use ballista_core::utils::create_grpc_server;
use ballista_scheduler::flight_sql::FlightSqlServiceImpl;
use config::prelude::*;
use datafusion::execution::context::default_session_builder;
+use tracing_subscriber::EnvFilter;
async fn start_server(
scheduler_name: String,
@@ -167,17 +168,30 @@ async fn main() -> Result<()> {
let port = opt.bind_port;
let log_dir = opt.log_dir;
let print_thread_info = opt.print_thread_info;
-
let scheduler_name = format!("scheduler_{}_{}_{}", namespace,
external_host, port);
- let log_file = tracing_appender::rolling::daily(log_dir, &scheduler_name);
-
- tracing_subscriber::fmt()
- .with_ansi(true)
- .with_thread_names(print_thread_info)
- .with_thread_ids(print_thread_info)
- .with_writer(log_file)
- .with_env_filter(special_mod_log_level)
- .init();
+
+ // File layer
+ if let Some(log_dir) = log_dir {
+ let log_file = tracing_appender::rolling::daily(log_dir,
&scheduler_name);
+ tracing_subscriber::fmt()
+ .with_ansi(true)
+ .with_thread_names(print_thread_info)
+ .with_thread_ids(print_thread_info)
+ .with_writer(log_file)
+ .with_env_filter(special_mod_log_level)
+ .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()));
+ 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)
+ .init();
+ }
let addr = format!("{}:{}", bind_host, port);
let addr = addr.parse()?;