zlog: Replace usages of env_logger in tests with zlog (#31436)

Also fixes:
https://github.com/zed-industries/zed/pull/31400#issuecomment-2908165249

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Ben Kunkle 2025-05-26 10:48:50 -05:00 committed by GitHub
parent 0c27aaecb3
commit c0aa8f63fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
66 changed files with 123 additions and 167 deletions

View file

@ -5,18 +5,38 @@ 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() {
process_env();
log::set_logger(&ZLOG).expect("Logger should not be initialized twice");
try_init().expect("Failed to initialize logger");
}
pub fn try_init() -> anyhow::Result<()> {
log::set_logger(&ZLOG).context("cannot be initialized twice")?;
log::set_max_level(log::LevelFilter::max());
process_env();
Ok(())
}
pub fn init_test() {
if get_env_config().is_some() {
if try_init().is_ok() {
init_output_stdout();
}
}
}
fn get_env_config() -> Option<String> {
std::env::var("ZED_LOG")
.or_else(|_| std::env::var("RUST_LOG"))
.ok()
}
pub fn process_env() {
let Ok(env_config) = std::env::var("ZED_LOG").or_else(|_| std::env::var("RUST_LOG")) else {
let Some(env_config) = get_env_config() else {
return;
};
match env_config::parse(&env_config) {