Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature support set level of logger #777

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want the RUST_LOG env var to have the highest precedence, so that they can override what's the in the config file as needed.

With this change, it's not possible to use RUST_LOG at all because min_level is set in defaults.toml, and always will override the env var.

Additionally, the env var supports much more than just static levels (like "info" or "warn")—it's able to completely configure the logger on a per-crate basis. For example:

RUST_LOG=info,arroyo_worker=debug,arroyo_controller=debug,arroyo_state=debug

I think an approach would be to:

  • First check if the env var is set, and if so use that with from_env_lossy; if not we can use the min_level config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank for @mwylde review, Sorry for later reply. I agree with Env var high priority, but I don't know how to implement min log level for each sub-crate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want the RUST_LOG env var to have the highest precedence, so that they can override what's the in the config file as needed.

With this change, it's not possible to use RUST_LOG at all because min_level is set in defaults.toml, and always will override the env var.

Additionally, the env var supports much more than just static levels (like "info" or "warn")—it's able to completely configure the logger on a per-crate basis. For example:

RUST_LOG=info,arroyo_worker=debug,arroyo_controller=debug,arroyo_state=debug

I think an approach would be to:

  • First check if the env var is set, and if so use that with from_env_lossy; if not we can use the min_level config.

parse level like this? first fetch ENV var then fetch min_level of logging config

let level_filter = std::env::var(EnvFilter::DEFAULT_ENV).unwrap_or(
        config()
            .logging
            .min_level
            .clone()
            .unwrap_or("info".to_string()),
    );

.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
Loading