Truncate --log file on open instead of appending
Each scpcap invocation now starts its log fresh. Appending meant a re-run after a failed attempt mixed new output in with (or could be mistaken for) stale output from the previous run -- confusing when diagnosing exactly this kind of issue in production.
This commit is contained in:
+4
-1
@@ -15,8 +15,11 @@ impl Logger {
|
|||||||
Logger(None)
|
Logger(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Truncates any existing file at `path` -- each run starts a fresh
|
||||||
|
/// log, so a re-run never leaves stale lines from a previous attempt
|
||||||
|
/// mixed in with (or mistaken for) the current one.
|
||||||
pub fn open(path: &Path) -> std::io::Result<Logger> {
|
pub fn open(path: &Path) -> std::io::Result<Logger> {
|
||||||
let f = OpenOptions::new().create(true).append(true).open(path)?;
|
let f = OpenOptions::new().create(true).write(true).truncate(true).open(path)?;
|
||||||
Ok(Logger(Some(Mutex::new(f))))
|
Ok(Logger(Some(Mutex::new(f))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user