set_msg_sink: Set the rtemis message sink

View source: R/msg.R

set_msg_sinkR Documentation

Set the rtemis message sink

Description

When set, msg(), msg0(), msgstart(), and msgdone() forward their structured output through sink instead of writing to the R console. Used by rtemis.server to capture training-time messages and forward them over a WebSocket connection. Pass NULL to restore default console output.

Usage

set_msg_sink(sink)

Arguments

sink

Function or NULL.

Details

The sink function is called once per message with a single argument: a list with fields

  • text: character. The formatted message body (no datetime prefix).

  • caller: character or NA. Calling function as identified by format_caller().

  • ts: character. Formatted timestamp ("%Y-%m-%d %H:%M:%S").

  • level: character. One of "info" (msg/msg0), "start" (msgstart), "done" (msgdone), or "progress" (progress_begin() / progress_update() / progress_end()).

Producers may include additional fields in the list, which sinks should ignore when not understood. In particular, the progress API in this package and rtemis's training observability emit execution-graph node events through the sink with these extra fields:

  • node_id: character. Unique id of the execution-graph node.

  • parent_id: character or NA. Parent node id (for nesting).

  • kind: character. Node kind (e.g. "tune", "grid_cell", "train_alg").

  • status: character. "start", "update", "done", "error", or "aborted".

  • current, total: integer or NA. Progress counters.

  • label: character. Display label without the counts (e.g. "Tuning"). text is the label and counts already composed for display; a sink that renders its own layout wants this instead of parsing them apart.

These are additive; sinks that only read the base fields keep working. Progress events fire regardless of verbosity (verbosity gates only the console renderer), and "update" events are throttled via getOption("rtemis.progress_throttle") - see progress_begin().

When a sink is set, the console output path is skipped for affected calls. Errors thrown by the sink propagate to the caller of msg().

Value

Previous sink (function or NULL), invisibly.

Author(s)

EDG

See Also

get_msg_sink(), with_msg_sink().

Examples

captured <- list()
set_msg_sink(function(m) captured[[length(captured) + 1L]] <<- m)
# msg("hello world")        # would append to `captured`
set_msg_sink(NULL)          # restore console output

rtemis.core documentation built on Sept. 20, 2026, 9:06 a.m.