Skip to content

Commit

Permalink
feat: Use info log level for crates named zksync_* by default
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Jun 21, 2024
1 parent c2412cf commit eee25cb
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions core/lib/vlog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,32 @@ impl ObservabilityBuilder {
subscriber.with(layer)
}

/// Builds a filter for the logs.
///
/// Uses `zksync=info` as a default which is then merged with user-defined directives.
/// Provided directives can extend/override the default value.
///
/// The provided default convers all the crates with a name starting with `zksync` (per `tracing`
/// [documentation][1]), which is a good enough default for any project.
///
/// If `log_directives` are provided via `with_log_directives`, they will be used.
/// Otherwise, the value will be parsed from the environment variable `RUST_LOG`.
///
/// [1]: https://docs.rs/tracing-subscriber/0.3.18/tracing_subscriber/filter/targets/struct.Targets.html#filtering-with-targets
fn build_filter(&self) -> EnvFilter {
let mut directives = "zksync=info,".to_string();
if let Some(log_directives) = &self.log_directives {
directives.push_str(log_directives);
} else if let Ok(env_directives) = std::env::var(EnvFilter::DEFAULT_ENV) {
directives.push_str(&env_directives);
};
EnvFilter::new(directives)
}

/// Initializes the observability subsystem.
pub fn build(self) -> ObservabilityGuard {
// Initialize logs.

let env_filter = if let Some(log_directives) = self.log_directives {
tracing_subscriber::EnvFilter::new(log_directives)
} else {
tracing_subscriber::EnvFilter::from_default_env()
};
let env_filter = self.build_filter();

match self.log_format {
LogFormat::Plain => {
Expand Down

0 comments on commit eee25cb

Please sign in to comment.