From 5c0911f12f43ee58906bca47a6b498f7028e9686 Mon Sep 17 00:00:00 2001 From: zhuliquan Date: Fri, 1 Nov 2024 17:06:05 +0800 Subject: [PATCH] feat: support set min-level of logger --- crates/arroyo-rpc/default.toml | 1 + crates/arroyo-rpc/src/config.rs | 4 ++++ crates/arroyo-server-common/src/lib.rs | 20 +++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/arroyo-rpc/default.toml b/crates/arroyo-rpc/default.toml index 13c81b537..c5aac357d 100644 --- a/crates/arroyo-rpc/default.toml +++ b/crates/arroyo-rpc/default.toml @@ -87,3 +87,4 @@ nonblocking = false enable-file-line = false enable-file-name = false buffered-lines-limit = 4096 +min-level = "INFO" # option: trace / debug / info / debug / error / all (i.e. trace) / off \ No newline at end of file diff --git a/crates/arroyo-rpc/src/config.rs b/crates/arroyo-rpc/src/config.rs index 9dc0442b2..dcfecf23c 100644 --- a/crates/arroyo-rpc/src/config.rs +++ b/crates/arroyo-rpc/src/config.rs @@ -626,6 +626,10 @@ pub struct LogConfig { #[serde(default)] pub format: LogFormat, + /// set min level for logger + #[serde(default)] + pub min_level: Option, + /// Nonblocking logging may reduce tail latency at the cost of higher memory usage #[serde(default)] pub nonblocking: bool, diff --git a/crates/arroyo-server-common/src/lib.rs b/crates/arroyo-server-common/src/lib.rs index 1f9b6cdc5..04a0ca8eb 100644 --- a/crates/arroyo-server-common/src/lib.rs +++ b/crates/arroyo-server-common/src/lib.rs @@ -54,11 +54,29 @@ pub fn init_logging(name: &str) -> Option { init_logging_with_filter( name, EnvFilter::builder() - .with_default_directive(LevelFilter::INFO.into()) + .with_default_directive(parse_level_filter().into()) .from_env_lossy(), ) } +fn parse_level_filter() -> LevelFilter { + let level_filter = config() + .logging + .min_level + .clone() + .unwrap_or(std::env::var(EnvFilter::DEFAULT_ENV).unwrap_or("info".to_string())); + + match level_filter.to_lowercase().as_str() { + "all" | "trace" => LevelFilter::TRACE, + "debug" => LevelFilter::DEBUG, + "info" => LevelFilter::INFO, + "warn" => LevelFilter::WARN, + "error" => LevelFilter::ERROR, + "off" => LevelFilter::OFF, + _ => LevelFilter::INFO, + } +} + macro_rules! register_log { ($e: expr, $nonblocking: expr, $filter: expr) => {{ let layer = $e;