Apply suggestions.

This commit is contained in:
vsrs 2021-01-27 00:59:31 +03:00
parent 0269071283
commit 5f1eb544da
2 changed files with 17 additions and 11 deletions

View file

@ -50,7 +50,8 @@ FLAGS:
-q, --quiet Set verbosity
--log-file <PATH> Log to the specified file instead of stderr
--no-buffering Flush log records to the file immediately
--no-log-buffering
Flush log records to the file immediately
--wait-dbg Wait until a debugger is attached to.
The flag is valid for debug builds only
@ -139,7 +140,7 @@ impl Args {
(false, true, true) => bail!("Invalid flags: -q conflicts with -v"),
};
let log_file = matches.opt_value_from_str("--log-file")?;
let no_buffering = matches.contains("--no-buffering");
let no_buffering = matches.contains("--no-log-buffering");
let wait_dbg = matches.contains("--wait-dbg");
if matches.contains(["-h", "--help"]) {

View file

@ -47,7 +47,8 @@ impl Log for Logger {
if !self.filter.matches(record) {
return;
}
match &self.file {
let should_flush = match &self.file {
Some(w) => {
let _ = writeln!(
w.lock(),
@ -56,16 +57,20 @@ impl Log for Logger {
record.module_path().unwrap_or_default(),
record.args(),
);
self.no_buffering
}
None => eprintln!(
"[{} {}] {}",
record.level(),
record.module_path().unwrap_or_default(),
record.args(),
),
}
None => {
eprintln!(
"[{} {}] {}",
record.level(),
record.module_path().unwrap_or_default(),
record.args(),
);
true // flush stderr unconditionally
}
};
if self.no_buffering {
if should_flush {
self.flush();
}
}