From bc2ee2d37436e4dda6344a551516f8ffa98f5793 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Fri, 28 Aug 2026 09:47:27 -0400 Subject: [PATCH] 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. --- src/tracelog.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tracelog.rs b/src/tracelog.rs index 799f205..c4915ff 100644 --- a/src/tracelog.rs +++ b/src/tracelog.rs @@ -15,8 +15,11 @@ impl Logger { 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 { - 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)))) }