get_logger: Get/Create a Logger

View source: R/get_logger.R

get_loggerR Documentation

Get/Create a Logger

Description

Get/Create a Logger

Usage

get_logger(name, class = Logger, reset = FALSE)

get_logger_glue(name)

Arguments

name

a character scalar or vector: The qualified name of the Logger as a hierarchical value.

class

An R6ClassGenerator object. Usually Logger or LoggerGlue are the only valid choices.

reset

a logical scalar. If TRUE the logger is reset to an unconfigured state. Unlike $config(NULL) this also replaces a LoggerGlue with vanilla Logger. Please note that this will invalidate Logger references created before the reset call (see examples).

Value

a Logger

Examples

lg <- get_logger("log/ger/test")
# equivalent to
lg <- get_logger(c("log", "ger", "test"))
lg$warn("a %s message", "warning")
lg
lg$parent

if (requireNamespace('glue')){
  lg <- get_logger_glue("log/ger")
}
lg$warn("a {.text} message", .text = "warning")

# completely reset 'glue' to an unconfigured vanilla Logger
get_logger("log/ger", reset = TRUE)
# WARNING: this invalidates existing references to the Logger
try(lg$info("lg has been invalidated an no longer works"))

lg <- get_logger("log/ger")
lg$info("now all is well again")

lgr documentation built on Sept. 6, 2022, 1:05 a.m.