MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / read_log_tail

Function read_log_tail

src/agents/cursor_diagnostics.rs:220–235  ·  view source on GitHub ↗

Reads a log file, capped to its final [`MAX_LOG_BYTES`] bytes.

(path: &Path)

Source from the content-addressed store, hash-verified

218
219/// Reads a log file, capped to its final [`MAX_LOG_BYTES`] bytes.
220fn read_log_tail(path: &Path) -> Option<String> {
221 use std::io::{Read, Seek, SeekFrom};
222
223 let mut file = std::fs::File::open(path).ok()?;
224 let len = file.metadata().ok()?.len();
225 if len > MAX_LOG_BYTES {
226 file.seek(SeekFrom::End(-(MAX_LOG_BYTES as i64))).ok()?;
227 }
228 let mut contents = String::new();
229 // Lossy-tolerant read: a mid-character seek point or stray bytes must not
230 // abort the whole scan.
231 let mut bytes = Vec::new();
232 file.read_to_end(&mut bytes).ok()?;
233 contents.push_str(&String::from_utf8_lossy(&bytes));
234 Some(contents)
235}
236
237#[cfg(test)]
238#[allow(clippy::unwrap_used, clippy::expect_used)]

Callers 1

scan_cursor_mcp_logsFunction · 0.85

Calls 1

metadataMethod · 0.80

Tested by

no test coverage detected