Re-use the open file when logging to file
This commit is contained in:
parent
6da08263be
commit
f49346c151
1 changed files with 8 additions and 11 deletions
|
|
@ -92,17 +92,14 @@ pub fn init_logging(opts: InitLoggingOptions) -> anyhow::Result<InitLoggingResul
|
||||||
);
|
);
|
||||||
if let Some(log_file) = &opts.log_file {
|
if let Some(log_file) = &opts.log_file {
|
||||||
let log_file = log_file.to_string();
|
let log_file = log_file.to_string();
|
||||||
let log_file = move || {
|
let log_file = std::sync::Mutex::new(LineWriter::new(
|
||||||
LineWriter::new(
|
std::fs::OpenOptions::new()
|
||||||
std::fs::OpenOptions::new()
|
.create(true)
|
||||||
.create(true)
|
.append(true)
|
||||||
.append(true)
|
.write(true)
|
||||||
.write(true)
|
.open(&log_file)
|
||||||
.open(&log_file)
|
.with_context(|| format!("error opening log file {:?}", log_file))?,
|
||||||
.with_context(|| format!("error opening log file {:?}", log_file))
|
));
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
layered
|
layered
|
||||||
.with(
|
.with(
|
||||||
fmt::layer()
|
fmt::layer()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue