Skip to contents

Closes the step opened by log_open() with the given id, cascading to any of its still-open descendants (deepest-first). With no id, closes the nearest open step, so simple last-in-first-out use needs no handle at all.

Usage

log_close(id = NULL, status = NULL)

Arguments

id

Step handle from log_open(). If omitted, the nearest open step is closed.

status

Optional character scalar overriding the step's final status: one of "success", "warning", or "error". Bypasses the usual elevation rule instead of comparing against it.

Value

A list with status and elapsed (seconds) for the step just closed, invisibly – the same values rendered on its Done line ("running" resolves to "success", as it does for display). NULL, invisibly, if there was no open step to close.

Details

A step's status only ever escalates via log_warn()/log_error() (see status elevation); it never comes back down on its own, so a step that logged an error and then recovered still closes with the error glyph. Pass status to override that explicitly – this force-assigns the step's final status regardless of what it escalated to. Because id = NULL resolves to the nearest open step for both log_open()-managed and log_step()-managed steps alike, this also lets you close (and override) a log_step() step early, before its automatic close-on-frame-exit fires.

See also

Examples

logtree_reset()
log_open("Step 1")
#>  Step 1
log_info("a child line")
#> ├─  a child line
log_close()
#> └─  Done  0.00s

logtree_reset()
log_open("Step 2")
#>  Step 2
log_error("failed once")
#> ├─  failed once
log_close(status = "success")  # recovered: override the elevated glyph
#> └─  Done  0.00s

logtree_reset()
log_open("Step 3")
#>  Step 3
result <- log_close()  # result$status, result$elapsed
#> └─  Done  0.00s