Get/Create a Logger

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




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


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


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).


a Logger


lg <- get_logger("log/ger/test") # equivalent to lg <- get_logger(c("log", "ger", "test")) lg$warn("a %s message", "warning")
#> WARN [11:20:22.828] a warning message
#> <Logger> [info] log/ger/test #> #> inherited appenders: #> console: <AppenderConsole> [all] -> console
#> <Logger> [info] log/ger #> #> inherited appenders: #> console: <AppenderConsole> [all] -> console
if (requireNamespace('glue')){ lg <- get_logger_glue("log/ger") } lg$warn("a {.text} message", .text = "warning")
#> WARN [11:20:22.837] a warning message
# completely reset 'glue' to an unconfigured vanilla Logger get_logger("log/ger", reset = TRUE)
#> <Logger> [info] log/ger #> #> inherited appenders: #> console: <AppenderConsole> [all] -> console
# WARNING: this invalidates existing references to the Logger try(lg$info("lg has been invalidated an no longer works"))
#> Warning: [2020-10-22 11:20:22.842] an error occurred during logging: Trying to log via a Logger reference that is no longer valid. Logger references become invalid when you reset a when you reset a Logger with `get_logger(reset = TRUE)`. Please re-create the Logger reference with with `get_logger(log/ger)`
lg <- get_logger("log/ger") lg$info("now all is well again")
#> INFO [11:20:22.845] now all is well again