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 {
|
||||
let log_file = log_file.to_string();
|
||||
let log_file = move || {
|
||||
LineWriter::new(
|
||||
std::fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.write(true)
|
||||
.open(&log_file)
|
||||
.with_context(|| format!("error opening log file {:?}", log_file))
|
||||
.unwrap(),
|
||||
)
|
||||
};
|
||||
let log_file = std::sync::Mutex::new(LineWriter::new(
|
||||
std::fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.write(true)
|
||||
.open(&log_file)
|
||||
.with_context(|| format!("error opening log file {:?}", log_file))?,
|
||||
));
|
||||
layered
|
||||
.with(
|
||||
fmt::layer()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue