Skip to content

Commit

Permalink
feat: support set min-level of logger
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuliquan committed Nov 5, 2024
1 parent 1ff9c60 commit 7ab913a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/arroyo-rpc/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions crates/arroyo-rpc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,10 @@ pub struct LogConfig {
#[serde(default)]
pub format: LogFormat,

/// set min level for logger
#[serde(default)]
pub min_level: Option<String>,

/// Nonblocking logging may reduce tail latency at the cost of higher memory usage
#[serde(default)]
pub nonblocking: bool,
Expand Down
20 changes: 19 additions & 1 deletion crates/arroyo-server-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,29 @@ pub fn init_logging(name: &str) -> Option<WorkerGuard> {
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;
Expand Down

0 comments on commit 7ab913a

Please sign in to comment.