1//! # zlog_settings
2use collections::HashMap;
3
4use gpui::App;
5use settings::{Settings, SettingsStore};
6
7pub fn init(cx: &mut App) {
8 ZlogSettings::register(cx);
9
10 cx.observe_global::<SettingsStore>(|cx| {
11 let zlog_settings = ZlogSettings::get_global(cx);
12 zlog::filter::refresh_from_settings(&zlog_settings.scopes);
13 })
14 .detach();
15}
16
17#[derive(Clone, Debug)]
18pub struct ZlogSettings {
19 /// A map of log scopes to the desired log level.
20 /// Useful for filtering out noisy logs or enabling more verbose logging.
21 ///
22 /// Example: {"log": {"client": "warn"}}
23 pub scopes: HashMap<String, String>,
24}
25
26impl Settings for ZlogSettings {
27 fn from_defaults(content: &settings::SettingsContent, _: &mut App) -> Self {
28 ZlogSettings {
29 scopes: content.log.clone().unwrap(),
30 }
31 }
32
33 fn refine(&mut self, content: &settings::SettingsContent, _: &mut App) {
34 if let Some(log) = &content.log {
35 self.scopes.extend(log.clone());
36 }
37 }
38
39 fn import_from_vscode(_: &settings::VsCodeSettings, _: &mut settings::SettingsContent) {}
40}