Skip to content

Commit

Permalink
refactor: use fs rename for log file rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
doums committed Sep 19, 2024
1 parent 0757a82 commit 786b746
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,12 @@ fn rotate_log_file(log_dir: PathBuf) -> Result<()> {
let log_file = log_dir.join(LOG_FILE);
if log_file.is_file() {
let old_file = log_dir.join(LOG_FILE_OLD);
let data = fs::read(&log_file).inspect_err(|e| {
fs::rename(&log_file, &old_file).inspect_err(|e| {
eprintln!(
"failed to read log file during log rotation {}: {e}",
"failed to rename log file during log rotation {}: {e}",
log_file.display()
)
})?;
fs::write(&old_file, data).inspect_err(|e| {
eprintln!(
"failed to write log file during log rotation {}: {e}",
old_file.display()
)
})?;
fs::remove_file(log_file)?;
}
Ok(())
}
Expand Down

0 comments on commit 786b746

Please sign in to comment.