Timing and Grouping
Problem
You need to measure how long a code block takes and group the related log entries so they are easy to correlate in output — without sprinkling Date.now() calls across the codebase.
Solution
Use time(label, fn) to measure execution and groupCollapsed(label, fn) to nest related log lines under a collapsible group in the console.
ts
import { Rune } from '@vielzeug/rune';
const result = await Rune.groupCollapsed('Checkout', async () => {
Rune.info('validating cart');
return Rune.time('process-order', () => processOrder(cart));
});Pitfalls
time()always emits atdebuglevel with the label as the log message and{ duration_ms }in context. IflogLevelis abovedebug, the timer still runs but no entry is emitted. SetlogLevel: 'debug'when capturing timing data.time()measures wall-clock time viaperformance.now(). For async functions, it covers total elapsed time including I/O wait — not CPU time. Long I/O waits will inflate the result.group()andgroupCollapsed()callconsole.group/console.groupEndregardless of which transport is configured. They are visual wrappers for the console; other transports (remote, JSON, batch) receive entries as normal flat events with no grouping semantics.- When
logLevelis'off', the group wrapper is bypassed entirely but the callback still executes.