add bounded history sink (#1)

This commit is contained in:
Nanaloveyuki
2026-08-11 13:30:58 +08:00
committed by GitHub
parent 0b05ee0c94
commit aab7a94ae2
38 changed files with 318 additions and 26 deletions
+34
View File
@@ -15,6 +15,40 @@ test "callback sink receives record" {
inspect(captured_message.val, content="hello")
}
///|
test "history sink retains the newest copied records" {
let sink = history_sink(capacity=2)
let logger = Logger::new(sink, min_level=Level::Info, target="history")
logger.info("one", fields=[field("position", "first")])
logger.info("two")
logger.info("three")
inspect(sink.capacity(), content="2")
inspect(sink.count(), content="2")
inspect(sink.dropped_count(), content="1")
let snapshot = sink.snapshot()
inspect(snapshot.length(), content="2")
inspect(snapshot[0].message, content="two")
inspect(snapshot[1].message, content="three")
snapshot[0].fields.push(field("mutated", "outside"))
inspect(sink.snapshot()[0].fields.length(), content="0")
}
///|
test "history sink normalizes capacity and clear resets its session" {
let sink = history_sink(capacity=0)
let logger = Logger::new(sink, min_level=Level::Info, target="history")
logger.info("one")
logger.info("two")
inspect(sink.capacity(), content="1")
inspect(sink.count(), content="1")
inspect(sink.dropped_count(), content="1")
sink.clear()
inspect(sink.count(), content="0")
inspect(sink.dropped_count(), content="0")
}
///|
test "split sink routes records by predicate" {
let left_messages : Ref[Array[String]] = Ref([])