Skip to content

Commit 780f476

Browse files
Merge #2451
2451: Use env_logger instead of flexi_logger r=matklad a=AlexanderEkdahl This fixes #2335 - By default only `error` will be printed. From what I can tell this matches the current behaviour. Configured through `RUST_LOG`. - I looked through the optional dependencies for `env_logger`and I have only enabled `human_time`. Without this feature no timestamp will be shown for log messages. - `RA_LOG_DIR` feature is removed This PR adds 2 new dependencies(`env_logger` and `human_time`) and removes 6 dependencies. Co-authored-by: Alexander Ekdahl <alexander@ekdahl.io>
2 parents 9712889 + 3fe539c commit 780f476

File tree

8 files changed

+28
-75
lines changed

8 files changed

+28
-75
lines changed

Cargo.lock

Lines changed: 21 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77

88
[dependencies]
99
pico-args = "0.3.0"
10-
flexi_logger = "0.14.0"
10+
env_logger = { version = "0.7.1", default-features = false, features = ["humantime"] }
1111

1212
ra_syntax = { path = "../ra_syntax" }
1313
ra_ide = { path = "../ra_ide" }

crates/ra_cli/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ mod progress_report;
77

88
use std::{error::Error, fmt::Write, io::Read};
99

10-
use flexi_logger::Logger;
1110
use pico_args::Arguments;
1211
use ra_ide::{file_structure, Analysis};
1312
use ra_prof::profile;
@@ -32,7 +31,7 @@ impl Verbosity {
3231
}
3332

3433
fn main() -> Result<()> {
35-
Logger::with_env_or_str("error").start()?;
34+
env_logger::try_init()?;
3635

3736
let subcommand = match std::env::args_os().nth(1) {
3837
None => {

crates/ra_lsp_server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ relative-path = "1.0.0"
1313
serde_json = "1.0.34"
1414
serde = { version = "1.0.83", features = ["derive"] }
1515
crossbeam-channel = "0.4"
16-
flexi_logger = "0.14.0"
1716
log = "0.4.3"
1817
lsp-types = { version = "0.61.0", features = ["proposed"] }
1918
rustc-hash = "1.0"
@@ -27,6 +26,7 @@ lsp-server = "0.3.0"
2726
ra_project_model = { path = "../ra_project_model" }
2827
ra_prof = { path = "../ra_prof" }
2928
ra_vfs_glob = { path = "../ra_vfs_glob" }
29+
env_logger = { version = "0.7.1", default-features = false, features = ["humantime"] }
3030

3131
[dev-dependencies]
3232
tempfile = "3"

crates/ra_lsp_server/src/main.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! `ra_lsp_server` binary
22
3-
use flexi_logger::{Duplicate, Logger};
43
use lsp_server::Connection;
54
use ra_lsp_server::{show_message, Result, ServerConfig};
65
use ra_prof;
@@ -14,11 +13,7 @@ fn main() -> Result<()> {
1413
fn setup_logging() -> Result<()> {
1514
std::env::set_var("RUST_BACKTRACE", "short");
1615

17-
let logger = Logger::with_env_or_str("error").duplicate_to_stderr(Duplicate::All);
18-
match std::env::var("RA_LOG_DIR") {
19-
Ok(ref v) if v == "1" => logger.log_to_file().directory("log").start()?,
20-
_ => logger.start()?,
21-
};
16+
env_logger::try_init()?;
2217

2318
ra_prof::set_filter(match std::env::var("RA_PROFILE") {
2419
Ok(spec) => ra_prof::Filter::from_spec(&spec),

crates/ra_lsp_server/tests/heavy_tests/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use tempfile::TempDir;
1515

1616
use crate::support::{project, Project};
1717

18-
const LOG: &'static str = "";
1918
const PROFILE: &'static str = "";
2019
// const PROFILE: &'static str = "*@3>100";
2120

crates/ra_lsp_server/tests/heavy_tests/support.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::{
77
};
88

99
use crossbeam_channel::{after, select, Receiver};
10-
use flexi_logger::Logger;
1110
use lsp_server::{Connection, Message, Notification, Request};
1211
use lsp_types::{
1312
notification::{DidOpenTextDocument, Exit},
@@ -53,7 +52,7 @@ impl<'a> Project<'a> {
5352
let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap());
5453
static INIT: Once = Once::new();
5554
INIT.call_once(|| {
56-
let _ = Logger::with_env_or_str(crate::LOG).start().unwrap();
55+
let _ = env_logger::builder().is_test(true).try_init().unwrap();
5756
ra_prof::set_filter(if crate::PROFILE.is_empty() {
5857
ra_prof::Filter::disabled()
5958
} else {

docs/dev/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ Logging is done by both rust-analyzer and VS Code, so it might be tricky to
124124
figure out where logs go.
125125

126126
Inside rust-analyzer, we use the standard `log` crate for logging, and
127-
`flexi_logger` for logging frotend. By default, log goes to stderr (the same as
128-
with `env_logger`), but the stderr itself is processed by VS Code. To mirror
129-
logs to a `./log` directory, set `RA_LOG_DIR=1` environmental variable.
127+
`env_logger` for logging frontend. By default, log goes to stderr, but the
128+
stderr itself is processed by VS Code.
130129

131130
To see stderr in the running VS Code instance, go to the "Output" tab of the
132131
panel and select `rust-analyzer`. This shows `eprintln!` as well. Note that

0 commit comments

Comments
 (0)