Registers a sink that keeps every event in a buffer instead of writing it
anywhere, so a run's logging can be asserted on rather than eyeballed.
Read the buffer back with logtree_sink_memory_events(). This is the
answer to "did my pipeline log what it should have?" – previously that meant
capturing console output and pattern-matching the rendered tree.
Arguments
- max
Maximum number of events to keep. Once the buffer is full the oldest events are dropped, so what you read back is always the most recent
max. Default1000.- threshold
Minimum leaf level to collect, as in
logtree_sink().NULL(the default) follows the globallogtree_threshold(); pass"debug"to collect everything a run logged regardless of what the console was set to show.
Value
The sink's id, invisibly – pass it to
logtree_sink_memory_events() to read the buffer, and to
logtree_sink_remove() to stop collecting.
Details
The buffer is dropped when the sink is removed with logtree_sink_remove(),
and it is capped: a long-running process cannot grow it without bound.
Examples
logtree_reset()
h <- logtree_sink_memory()
f <- function() {
log_step("Load data")
log_warn("coerced 3 rows")
}
invisible(f())
#> ▶ Load data
#> ├─ ⚠ coerced 3 rows
#> └─ ⚠ Done 0.01s
events <- logtree_sink_memory_events(h)
events[, c("level", "label", "status")]
#> level label status
#> 1 open Load data step
#> 2 leaf coerced 3 rows warning
#> 3 close Load data warning
logtree_sink_remove(h)
