Skip to content

Commit 7e45727

Browse files
committed
Unify logging
HELIX_LOG_LEVEL env variable can now also be set in a non integration test environment.
1 parent 95b227a commit 7e45727

File tree

3 files changed

+21
-38
lines changed

3 files changed

+21
-38
lines changed

helix-term/src/application.rs

-25
Original file line numberDiff line numberDiff line change
@@ -79,28 +79,6 @@ pub struct Application {
7979
last_render: Instant,
8080
}
8181

82-
#[cfg(feature = "integration")]
83-
fn setup_integration_logging() {
84-
let level = std::env::var("HELIX_LOG_LEVEL")
85-
.map(|lvl| lvl.parse().unwrap())
86-
.unwrap_or(log::LevelFilter::Info);
87-
88-
// Separate file config so we can include year, month and day in file logs
89-
let _ = fern::Dispatch::new()
90-
.format(|out, message, record| {
91-
out.finish(format_args!(
92-
"{} {} [{}] {}",
93-
chrono::Local::now().format("%Y-%m-%dT%H:%M:%S%.3f"),
94-
record.target(),
95-
record.level(),
96-
message
97-
))
98-
})
99-
.level(level)
100-
.chain(std::io::stdout())
101-
.apply();
102-
}
103-
10482
fn restore_term() -> Result<(), Error> {
10583
let mut stdout = stdout();
10684
// reset cursor shape
@@ -125,9 +103,6 @@ impl Application {
125103
theme: Theme,
126104
langauge_configurations: LanguageConfigurations,
127105
) -> Result<Self, Error> {
128-
#[cfg(feature = "integration")]
129-
setup_integration_logging();
130-
131106
#[cfg(not(feature = "integration"))]
132107
let backend = CrosstermBackend::new(stdout());
133108
#[cfg(feature = "integration")]

helix-term/src/main.rs

+20-12
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,25 @@ async fn main_impl() -> Result<i32> {
9898
}
9999

100100
fn setup_logging(logpath: Option<PathBuf>, verbosity: u64) -> Result<()> {
101-
helix_loader::setup_log_file(logpath);
101+
let log_level = match verbosity {
102+
0 => std::env::var("HELIX_LOG_LEVEL")?
103+
.parse()
104+
.unwrap_or(log::LevelFilter::Warn),
105+
1 => log::LevelFilter::Info,
106+
2 => log::LevelFilter::Debug,
107+
_3_or_more => log::LevelFilter::Trace,
108+
};
109+
110+
#[cfg(feature = "integration")]
111+
let logger: fern::Output = std::io::stdout().into();
102112

103-
let mut base_config = fern::Dispatch::new();
104-
base_config = match verbosity {
105-
0 => base_config.level(log::LevelFilter::Warn),
106-
1 => base_config.level(log::LevelFilter::Info),
107-
2 => base_config.level(log::LevelFilter::Debug),
108-
_3_or_more => base_config.level(log::LevelFilter::Trace),
113+
#[cfg(not(feature = "integration"))]
114+
let logger: fern::Output = {
115+
helix_loader::setup_log_file(logpath);
116+
fern::log_file(helix_loader::log_file())?.into()
109117
};
110118

111-
// Separate file config so we can include year, month and day in file logs
112-
let file_config = fern::Dispatch::new()
119+
fern::Dispatch::new()
113120
.format(|out, message, record| {
114121
out.finish(format_args!(
115122
"{} {} [{}] {}",
@@ -119,7 +126,8 @@ fn setup_logging(logpath: Option<PathBuf>, verbosity: u64) -> Result<()> {
119126
message
120127
))
121128
})
122-
.chain(fern::log_file(helix_loader::log_file())?);
123-
base_config.chain(file_config).apply()?;
124-
Ok(())
129+
.level(log_level)
130+
.chain(logger)
131+
.apply()
132+
.map_err(|err| anyhow::anyhow!(err))
125133
}

helix-term/src/ui/editor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ impl EditorView {
794794
let mut last_mode = mode;
795795
self.pseudo_pending.extend(self.keymap.pending());
796796
let key_result = self.keymap.get(mode, event);
797-
let sort_infobox = cxt.editor.config.load().sorted_infobox;
797+
let sort_infobox = cxt.editor.config().sorted_infobox;
798798
cxt.editor.autoinfo = self
799799
.keymap
800800
.sticky_keytrie()

0 commit comments

Comments
 (0)