Skip to content

Commit 9a9ed21

Browse files
committed
allow configurable log level
1 parent ebab8c8 commit 9a9ed21

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
"type": "boolean",
6565
"default": false,
6666
"description": "[DEBUG] Enable to skip bootstrapping the language server binary from Github. Set this to use a manually provided language server binary."
67+
},
68+
"mcglsl.logLevel": {
69+
"type": "string",
70+
"default": "info",
71+
"enum": ["trace", "debug", "info", "warn", "error"],
72+
"description": "Change the log level of the language server. This change happens live and does not require a restart."
6773
}
6874
}
6975
}

server/src/configuration.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use std::str::FromStr;
2+
3+
use slog::Level;
4+
use slog_scope::error;
5+
6+
7+
pub fn handle_log_level_change<F: FnOnce(Level)>(log_level: String, callback: F) {
8+
match Level::from_str(log_level.as_str()) {
9+
Ok(level) => callback(level),
10+
Err(_) => error!("got unexpected log level from config"; "level" => log_level),
11+
};
12+
}

server/src/main.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use lazy_static::lazy_static;
4040
mod commands;
4141
mod consts;
4242
mod dfs;
43+
mod configuration;
4344
mod graph;
4445
mod lsp_ext;
4546
mod merge_views;
@@ -604,6 +605,20 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
604605

605606
fn workspace_change_configuration(&mut self, params: DidChangeConfigurationParams) {
606607
logging::slog_with_trace_id(|| {
608+
#[derive(Deserialize)]
609+
struct Configuration {
610+
#[serde(alias ="logLevel")]
611+
log_level: String
612+
}
613+
614+
let config: Configuration = from_value(params.settings.as_object().unwrap().get("mcglsl").unwrap().to_owned()).unwrap();
615+
616+
info!("got updated configuration"; "config" => params.settings.as_object().unwrap().get("mcglsl").unwrap().to_string());
617+
618+
configuration::handle_log_level_change(config.log_level, |level| {
619+
self._log_guard = None; // set to None so Drop is invoked
620+
self._log_guard = Some(logging::set_logger_with_level(level));
621+
})
607622
});
608623
}
609624

0 commit comments

Comments
 (0)