From fdaaa558c9315bf5b3bdc203d45c655a1de4fe8d Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 15 Sep 2025 17:16:16 -0600 Subject: [PATCH] zlog settings Co-authored-by: Ben Kunkle --- Cargo.lock | 4 +- crates/settings/src/settings_content.rs | 6 +++ crates/zlog/Cargo.toml | 1 + crates/zlog/src/filter.rs | 11 +++--- crates/zlog_settings/Cargo.toml | 3 +- crates/zlog_settings/src/zlog_settings.rs | 45 ++++++++++------------- 6 files changed, 34 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f37ab3db52b125dd31dd742b64a2529a094ab4d5..6e2845aabe589d688343a6216c2b13f7a92d3308 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21001,6 +21001,7 @@ version = "0.1.0" dependencies = [ "anyhow", "chrono", + "collections", "log", "tempfile", "workspace-hack", @@ -21011,9 +21012,8 @@ name = "zlog_settings" version = "0.1.0" dependencies = [ "anyhow", + "collections", "gpui", - "schemars", - "serde", "settings", "workspace-hack", "zlog", diff --git a/crates/settings/src/settings_content.rs b/crates/settings/src/settings_content.rs index e93cd2fb05ea2c6331bda90e363d90b5265674ef..a08b6b77b79a70190cb45a9d89fe3f5c75679d76 100644 --- a/crates/settings/src/settings_content.rs +++ b/crates/settings/src/settings_content.rs @@ -39,6 +39,12 @@ pub struct SettingsContent { /// Configuration of audio in Zed. pub audio: Option, + + /// A map of log scopes to the desired log level. + /// Useful for filtering out noisy logs or enabling more verbose logging. + /// + /// Example: {"log": {"client": "warn"}} + pub log: Option>, } impl SettingsContent { diff --git a/crates/zlog/Cargo.toml b/crates/zlog/Cargo.toml index d0632d14f2d5b9ca6f26d7f9cbcbb8a341104860..4b758437d5e1608aaa68e86f90215f57b928e883 100644 --- a/crates/zlog/Cargo.toml +++ b/crates/zlog/Cargo.toml @@ -15,6 +15,7 @@ path = "src/zlog.rs" default = [] [dependencies] +collections.workspace = true chrono.workspace = true log.workspace = true workspace-hack.workspace = true diff --git a/crates/zlog/src/filter.rs b/crates/zlog/src/filter.rs index 31a58894774e6c0d08ea22b585350eb26ff09907..9a2de13cb3d33a1a6f4d17f7eddd4754cae40ea3 100644 --- a/crates/zlog/src/filter.rs +++ b/crates/zlog/src/filter.rs @@ -1,9 +1,8 @@ -use std::{ - collections::{HashMap, VecDeque}, - sync::{ - OnceLock, RwLock, - atomic::{AtomicU8, Ordering}, - }, +use collections::HashMap; +use std::collections::VecDeque; +use std::sync::{ + OnceLock, RwLock, + atomic::{AtomicU8, Ordering}, }; use crate::{SCOPE_DEPTH_MAX, SCOPE_STRING_SEP_STR, Scope, ScopeAlloc, env_config, private}; diff --git a/crates/zlog_settings/Cargo.toml b/crates/zlog_settings/Cargo.toml index 2555d18aadc162161eb3aedf5c948385f347c6cc..00c81e0ef45863d36014d63ac5e07d690c507207 100644 --- a/crates/zlog_settings/Cargo.toml +++ b/crates/zlog_settings/Cargo.toml @@ -17,8 +17,7 @@ default = [] [dependencies] anyhow.workspace = true gpui.workspace = true -schemars.workspace = true -serde.workspace = true +collections.workspace = true settings.workspace = true zlog.workspace = true workspace-hack.workspace = true diff --git a/crates/zlog_settings/src/zlog_settings.rs b/crates/zlog_settings/src/zlog_settings.rs index dd74fc574ff23dc78beca1feafeb34d874a68c22..fc350e035b8f42ad6ab6515960e6506637de2b31 100644 --- a/crates/zlog_settings/src/zlog_settings.rs +++ b/crates/zlog_settings/src/zlog_settings.rs @@ -1,9 +1,8 @@ //! # zlog_settings -use anyhow::Result; +use collections::HashMap; + use gpui::App; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use settings::{Settings, SettingsKey, SettingsStore, SettingsUi}; +use settings::{Settings, SettingsStore}; pub fn init(cx: &mut App) { ZlogSettings::register(cx); @@ -15,33 +14,27 @@ pub fn init(cx: &mut App) { .detach(); } -#[derive( - Clone, - Debug, - Default, - Serialize, - Deserialize, - PartialEq, - Eq, - JsonSchema, - SettingsUi, - SettingsKey, -)] -#[settings_key(key = "log")] +#[derive(Clone, Debug)] pub struct ZlogSettings { - #[serde(default, flatten)] - pub scopes: std::collections::HashMap, + /// A map of log scopes to the desired log level. + /// Useful for filtering out noisy logs or enabling more verbose logging. + /// + /// Example: {"log": {"client": "warn"}} + pub scopes: HashMap, } impl Settings for ZlogSettings { - type FileContent = Self; + fn from_default(content: &settings::SettingsContent, _: &mut App) -> Option { + Some(ZlogSettings { + scopes: content.log.clone()?, + }) + } - fn load(sources: settings::SettingsSources, _: &mut App) -> Result - where - Self: Sized, - { - sources.json_merge() + fn refine(&mut self, content: &settings::SettingsContent, _: &mut App) { + if let Some(log) = &content.log { + self.scopes.extend(log.clone()); + } } - fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {} + fn import_from_vscode(_: &settings::VsCodeSettings, _: &mut settings::SettingsContent) {} }