Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Initialize zlog default filters on init rather than waiting for settings load (#32209)
Michael Sloan3e8565ac25a7
diff --git a/crates/zlog/src/filter.rs b/crates/zlog/src/filter.rsindex 7d51df88615..56350d34c3c 100644--- a/crates/zlog/src/filter.rs+++ b/crates/zlog/src/filter.rs@@ -38,11 +38,11 @@ pub static LEVEL_ENABLED_MAX_CONFIG: AtomicU8 = AtomicU8::new(LEVEL_ENABLED_MAX_const DEFAULT_FILTERS: &[(&str, log::LevelFilter)] = &[#[cfg(any(target_os = "linux", target_os = "freebsd"))]- ("zbus", log::LevelFilter::Off),+ ("zbus", log::LevelFilter::Warn),#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "windows"))]- ("blade_graphics", log::LevelFilter::Off),+ ("blade_graphics", log::LevelFilter::Warn),#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "windows"))]- ("naga::back::spv::writer", log::LevelFilter::Off),+ ("naga::back::spv::writer", log::LevelFilter::Warn),];pub fn init_env_filter(filter: env_config::EnvFilter) {@@ -90,10 +90,6 @@ pub fn is_scope_enabled(scope: &Scope, module_path: Option<&str>, level: log::Le};}-pub(crate) fn refresh() {- refresh_from_settings(&HashMap::default());-}-pub fn refresh_from_settings(settings: &HashMap<String, String>) {let env_config = ENV_FILTER.get();let map_new = ScopeMap::new_from_settings_and_env(settings, env_config, DEFAULT_FILTERS);diff --git a/crates/zlog/src/zlog.rs b/crates/zlog/src/zlog.rsindex d8b685e57fb..570c82314c5 100644--- a/crates/zlog/src/zlog.rs+++ b/crates/zlog/src/zlog.rs@@ -5,19 +5,25 @@ mod env_config;pub mod filter;pub mod sink;-use anyhow::Context;pub use sink::{flush, init_output_file, init_output_stdout};pub const SCOPE_DEPTH_MAX: usize = 4;pub fn init() {- try_init().expect("Failed to initialize logger");+ match try_init() {+ Err(err) => {+ log::error!("{err}");+ eprintln!("{err}");+ }+ Ok(()) => {}+ }}pub fn try_init() -> anyhow::Result<()> {- log::set_logger(&ZLOG).context("cannot be initialized twice")?;+ log::set_logger(&ZLOG)?;log::set_max_level(log::LevelFilter::max());process_env();+ filter::refresh_from_settings(&std::collections::HashMap::default());Ok(())}@@ -42,7 +48,6 @@ pub fn process_env() {match env_config::parse(&env_config) {Ok(filter) => {filter::init_env_filter(filter);- filter::refresh();}Err(err) => {eprintln!("Failed to parse log filter: {}", err);