Skip to content

Commit d6ea756

Browse files
authored
Merge pull request #158 from intel/respect-config-loglevel
Update global log-level from config
2 parents 88d9e9e + 5992991 commit d6ea756

File tree

9 files changed

+35
-5
lines changed

9 files changed

+35
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
(in some cases), resulting in performance improvements.
1818
- The DLS will now try to stop ongoing work when asked to shut down,
1919
which should make it exit faster.
20+
- Adjusted error message in DFA when unable to open DLS binary
21+
- The DLS will now update the internal log-level when after a configuration
22+
update
2023

2124
## 0.9.13
2225
- Corrected the name of "explicit\_param\_decls" provisional. Note that it still

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ itertools = "0.14"
3636
jsonrpc = "0.18"
3737
lsp-types = { version = "0.97" }
3838
lazy_static = "1.4"
39-
log = "0.4"
39+
log = {version = "0.4", features = ["serde"]}
4040
logos = "0.15"
4141
rayon = "1"
4242
regex = "1.5.5"

src/actions/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,11 @@ impl <O: Output> InitActionContext<O> {
720720
self.report_errors(out);
721721
},
722722
}
723+
724+
// Re-update log level
725+
if let Some(level) = self.config.lock().unwrap().server_debug_level {
726+
crate::logging::set_global_log_level(level);
727+
}
723728
}
724729

725730
// Call before adding new analysis

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub struct Config {
132132
pub lint_cfg_path: Option<PathBuf>,
133133
pub lint_direct_only: bool,
134134
pub no_default_features: bool,
135+
pub server_debug_level: Option<log::LevelFilter>,
135136
// pub jobs: Option<u32>,
136137
pub compile_info_path: Option<PathBuf>,
137138
pub analysis_retain_duration: Option<f64>,
@@ -216,6 +217,7 @@ impl Default for Config {
216217
linting_enabled: true,
217218
lint_cfg_path: None,
218219
lint_direct_only: true,
220+
server_debug_level: None,
219221
no_default_features: false,
220222
compile_info_path: None,
221223
analysis_retain_duration: None,

src/dfa/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ use clap::{command, arg, Arg, ArgAction};
1616

1717
use dls::dfa::ClientInterface;
1818

19+
1920
use log::debug;
2021

2122
pub fn main() {
22-
env_logger::init();
23+
dls::logging::init();
2324
let code = main_inner();
2425
std::process::exit(match code {
2526
Ok(()) => 0,
@@ -143,7 +144,7 @@ fn main_inner() -> Result<(), i32> {
143144
let mut dlsclient = ClientInterface::start(&arg.binary, root, linting_enabled)
144145
.map_err(|e|{
145146
std::io::stdout().write_all(
146-
format!("Failed to open client binary: {}\n",
147+
format!("Failed to start client: {}\n",
147148
e).as_bytes())
148149
.ok();
149150
1})?;

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub mod utility;
4444
pub mod vfs;
4545
#[cfg(test)]
4646
pub mod test;
47+
pub mod logging;
4748

4849
type Span = span::Span<span::ZeroIndexed>;
4950

src/lint/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ pub mod tests {
559559
use crate::lint::rules::Rule;
560560
use crate::analysis::ZeroRange;
561561

562-
env_logger::init();
562+
crate::logging::init();
563563

564564
let source =
565565
"

src/logging.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// © 2024 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0 and MIT
3+
4+
pub fn init() {
5+
// Slightly dumb way to do this, build the logger once with defaults
6+
// to get the max level for all modules from env, then build again
7+
// to remove this restriction and place it on log:: instead
8+
let dummy_logger = env_logger::Builder::from_default_env().build();
9+
let max_level = dummy_logger.filter();
10+
env_logger::Builder::from_default_env()
11+
.filter_level(log::LevelFilter::Trace)
12+
.init();
13+
set_global_log_level(max_level);
14+
}
15+
16+
pub fn set_global_log_level(level: log::LevelFilter) {
17+
log::set_max_level(level);
18+
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use clap::{Parser, command, arg};
1313
/// The main entry point to the DLS.
1414
// Parses CLI arguments and then runs the server.
1515
pub fn main() {
16-
env_logger::init();
16+
dls::logging::init();
1717
let exit_code = main_inner();
1818
std::process::exit(exit_code);
1919
}

0 commit comments

Comments
 (0)