Bridges the logger package (https://daroczig.github.io/logger/) into
logtree's tree rendering. logger's own per-call pipeline is
formatter() -> layout() -> appender(): only the layout stage receives
the structured level object (an integer with a "level" attribute
such as "INFO") – appender() only ever sees a pre-formatted
character line – so a custom layout, not a custom appender, is the
correct integration point. Register it as logger's layout and pair it
with logger::appender_void (a ready-made no-op) so that logtree's
rendering, which happens as a side effect of the layout call, is the
only visible output:
Usage
layout_logtree(
level,
msg,
namespace = NA_character_,
.logcall = sys.call(),
.topcall = sys.call(-1),
.topenv = parent.frame(),
.timestamp = Sys.time()
)Arguments
- level
A
loggerlog level object (e.g.logger::INFO), as passed in bylogger's internal dispatch.- msg
Character scalar, already formatted by
logger's formatter stage (glue interpolation has already happened by this point).- namespace, .logcall, .timestamp
Unused; accepted only because
logger's dispatcher calls every layout with this exact signature (seelogger::layout_simple).- .topcall
The call
loggerwas invoked from, supplied by its dispatcher. Used as the leaf's call site for thetracecolumn.- .topenv
Unused; part of
logger's layout signature.
Value
character(0), invisibly. The record is discarded by
logger::appender_void() regardless, so its content is irrelevant;
a zero-length character vector matches logger's layout contract.
Details
logger::log_layout(logtree::layout_logtree)
logger::log_appender(logger::appender_void)logger severities map onto logtree leaf levels as: FATAL/ERROR ->
log_error(), WARN -> log_warn(), SUCCESS -> log_success(),
INFO -> log_info(), DEBUG/TRACE -> log_debug() (logger has
two debug-ish tiers, logtree has one, so both collapse to the same
leaf). Note logger's own log_threshold() already gates before the
layout is ever invoked; logtree_threshold() is then an
independent, second gate applied on top of that – both legitimately
apply at once, this is not a bug.
When the trace theme slot is on, the leaf's call site is taken from
logger's own .topcall rather than from logtree's usual frame walk. That
matters: this layout is what calls the leaf, so a frame walk would report
layout_logtree as the origin of every routed line instead of the
logger::log_info() call in your code.
Examples
if (rlang::is_installed("logger", version = "0.3.0")) {
logtree_reset()
logger::log_layout(layout_logtree, namespace = "logtree_demo")
logger::log_appender(logger::appender_void, namespace = "logtree_demo")
log_step("Demo step")
logger::log_info("hello", namespace = "logtree_demo")
}
#> ▶ Demo step
#> ├─ ℹ hello
#> └─ ◌ Done 0.01s
