use std::sync::{Arc, Mutex};
use ticklog::{info, Level, LogSink};
struct CaptureSink {
lines: Arc<Mutex<Vec<String>>>,
}
impl LogSink for CaptureSink {
fn accept(&mut self, line: &[u8], _level: Level) -> std::io::Result<()> {
self.lines
.lock()
.unwrap()
.push(String::from_utf8_lossy(line).into_owned());
Ok(())
}
}
#[test]
fn oversized_record_is_dropped_and_next_record_survives() {
let lines = Arc::new(Mutex::new(Vec::new()));
let sink = CaptureSink {
lines: Arc::clone(&lines),
};
let guard = ticklog::builder()
.sink(sink)
.max_level(Level::Trace)
.build()
.expect("first build in a fresh process must succeed");
let huge = "x".repeat(70_000);
info!("huge={}", huge);
info!("sentinel={}", 42u64);
drop(guard);
let captured = lines.lock().unwrap();
assert!(
captured.iter().any(|l| l.ends_with("sentinel=42")),
"sentinel record must survive the oversized record; got {captured:?}"
);
assert!(
captured.iter().all(|l| !l.contains("huge=")),
"oversized record must be dropped, not emitted; got {captured:?}"
);
}