summaryrefslogtreecommitdiff
path: root/cli/lsp/logging.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp/logging.rs')
-rw-r--r--cli/lsp/logging.rs35
1 files changed, 33 insertions, 2 deletions
diff --git a/cli/lsp/logging.rs b/cli/lsp/logging.rs
index 7099b08bc..8b703f2a5 100644
--- a/cli/lsp/logging.rs
+++ b/cli/lsp/logging.rs
@@ -6,6 +6,8 @@ use std::sync::atomic::Ordering;
static LSP_DEBUG_FLAG: AtomicBool = AtomicBool::new(false);
static LSP_LOG_LEVEL: AtomicUsize = AtomicUsize::new(log::Level::Info as usize);
+static LSP_WARN_LEVEL: AtomicUsize =
+ AtomicUsize::new(log::Level::Warn as usize);
pub fn set_lsp_debug_flag(value: bool) {
LSP_DEBUG_FLAG.store(value, Ordering::SeqCst)
@@ -15,6 +17,7 @@ pub fn lsp_debug_enabled() -> bool {
LSP_DEBUG_FLAG.load(Ordering::SeqCst)
}
+/// Change the lsp to log at the provided level.
pub fn set_lsp_log_level(level: log::Level) {
LSP_LOG_LEVEL.store(level as usize, Ordering::SeqCst)
}
@@ -28,13 +31,40 @@ pub fn lsp_log_level() -> log::Level {
}
}
+/// Change the lsp to warn at the provided level.
+pub fn set_lsp_warn_level(level: log::Level) {
+ LSP_WARN_LEVEL.store(level as usize, Ordering::SeqCst)
+}
+
+pub fn lsp_warn_level() -> log::Level {
+ let level = LSP_LOG_LEVEL.load(Ordering::SeqCst);
+ // TODO(bartlomieju):
+ #[allow(clippy::undocumented_unsafe_blocks)]
+ unsafe {
+ std::mem::transmute(level)
+ }
+}
+
/// Use this macro to do "info" logs in the lsp code. This allows
/// for downgrading these logs to another log level in the REPL.
macro_rules! lsp_log {
($($arg:tt)+) => (
- let lsp_log_level = crate::lsp::logging::lsp_log_level();
+ let lsp_log_level = $crate::lsp::logging::lsp_log_level();
+ if lsp_log_level == log::Level::Debug {
+ $crate::lsp::logging::lsp_debug!($($arg)+)
+ } else {
+ log::log!(lsp_log_level, $($arg)+)
+ }
+ )
+}
+
+/// Use this macro to do "warn" logs in the lsp code. This allows
+/// for downgrading these logs to another log level in the REPL.
+macro_rules! lsp_warn {
+ ($($arg:tt)+) => (
+ let lsp_log_level = $crate::lsp::logging::lsp_warn_level();
if lsp_log_level == log::Level::Debug {
- crate::lsp::logging::lsp_debug!($($arg)+)
+ $crate::lsp::logging::lsp_debug!($($arg)+)
} else {
log::log!(lsp_log_level, $($arg)+)
}
@@ -51,3 +81,4 @@ macro_rules! lsp_debug {
pub(super) use lsp_debug;
pub(super) use lsp_log;
+pub(super) use lsp_warn;