allow configurable log level

This commit is contained in:
Noah Santschi-Cooney 2022-03-18 19:11:48 +00:00
parent ebab8c899a
commit 9a9ed21f13
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48
3 changed files with 33 additions and 0 deletions

View file

@ -0,0 +1,12 @@
use std::str::FromStr;
use slog::Level;
use slog_scope::error;
pub fn handle_log_level_change<F: FnOnce(Level)>(log_level: String, callback: F) {
match Level::from_str(log_level.as_str()) {
Ok(level) => callback(level),
Err(_) => error!("got unexpected log level from config"; "level" => log_level),
};
}

View file

@ -40,6 +40,7 @@ use lazy_static::lazy_static;
mod commands;
mod consts;
mod dfs;
mod configuration;
mod graph;
mod lsp_ext;
mod merge_views;
@ -604,6 +605,20 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
fn workspace_change_configuration(&mut self, params: DidChangeConfigurationParams) {
logging::slog_with_trace_id(|| {
#[derive(Deserialize)]
struct Configuration {
#[serde(alias ="logLevel")]
log_level: String
}
let config: Configuration = from_value(params.settings.as_object().unwrap().get("mcglsl").unwrap().to_owned()).unwrap();
info!("got updated configuration"; "config" => params.settings.as_object().unwrap().get("mcglsl").unwrap().to_string());
configuration::handle_log_level_change(config.log_level, |level| {
self._log_guard = None; // set to None so Drop is invoked
self._log_guard = Some(logging::set_logger_with_level(level));
})
});
}