mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-07-24 11:44:44 +00:00
allow configurable log level
This commit is contained in:
parent
ebab8c899a
commit
9a9ed21f13
3 changed files with 33 additions and 0 deletions
12
server/src/configuration.rs
Normal file
12
server/src/configuration.rs
Normal 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),
|
||||
};
|
||||
}
|
|
@ -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));
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue