zlog: Init (#27273)
Scaffolding for a revised way of logging in Zed. Very WIP, but the idea is to allow maintainers to tell users to paste ```json { "log": { "project.format": "trace" } } ``` into their settings so that even trace logs are emitted for the log statements emitted from a logger under the `project.format` scope. The plan is to eventually implement the `Log` trait from the `log` crate instead of just wrapping the `log` crate, which will simplify the implementation greatly, and remove our need for both the `env_logger` and `simplelog` crates. Additionally, work will be done to transition to using the scoped logging APIs throughout the app, focusing on bug hotspots to start (currently, scoped logging is only used in the format codepath). Release Notes: - N/A
This commit is contained in:
parent
b32c792b68
commit
16ad7424d6
12 changed files with 656 additions and 29 deletions
23
crates/zlog_settings/Cargo.toml
Normal file
23
crates/zlog_settings/Cargo.toml
Normal file
|
@ -0,0 +1,23 @@
|
|||
[package]
|
||||
name = "zlog_settings"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
publish.workspace = true
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/zlog_settings.rs"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
gpui.workspace = true
|
||||
schemars.workspace = true
|
||||
serde.workspace = true
|
||||
settings.workspace = true
|
||||
zlog.workspace = true
|
1
crates/zlog_settings/LICENSE-GPL
Symbolic link
1
crates/zlog_settings/LICENSE-GPL
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../LICENSE-GPL
|
35
crates/zlog_settings/src/zlog_settings.rs
Normal file
35
crates/zlog_settings/src/zlog_settings.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
//! # zlog_settings
|
||||
use anyhow::Result;
|
||||
use gpui::App;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use settings::{Settings, SettingsStore};
|
||||
|
||||
pub fn init(cx: &mut App) {
|
||||
ZlogSettings::register(cx);
|
||||
|
||||
cx.observe_global::<SettingsStore>(|cx| {
|
||||
let zlog_settings = ZlogSettings::get_global(cx);
|
||||
zlog::scope_map::refresh(&zlog_settings.scopes);
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
pub struct ZlogSettings {
|
||||
#[serde(default, flatten)]
|
||||
pub scopes: std::collections::HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl Settings for ZlogSettings {
|
||||
const KEY: Option<&'static str> = Some("log");
|
||||
|
||||
type FileContent = Self;
|
||||
|
||||
fn load(sources: settings::SettingsSources<Self::FileContent>, _: &mut App) -> Result<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
sources.json_merge()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue