Get or set log record appender function
Arguments
- appender
function delivering a log record to the destination, eg
appender_console()
,appender_file()
orappender_tee()
, default NULL- namespace
logger namespace
- index
index of the logger within the namespace
See also
Other log configutation functions:
log_formatter()
,
log_layout()
,
log_threshold()
Examples
## change appender to "tee" that writes to the console and a file as well
t <- tempfile()
log_appender(appender_tee(t))
log_info(42)
#> INFO [2024-10-21 07:31:18] 42
log_info(43)
#> INFO [2024-10-21 07:31:18] 43
log_info(44)
#> INFO [2024-10-21 07:31:18] 44
readLines(t)
#> [1] "INFO [2024-10-21 07:31:18] 42" "INFO [2024-10-21 07:31:18] 43"
#> [3] "INFO [2024-10-21 07:31:18] 44"
## poor man's tee by stacking loggers in the namespace
t <- tempfile()
log_appender(appender_stdout)
log_appender(appender_file(t), index = 2)
log_info(42)
#> INFO [2024-10-21 07:31:18] 42
readLines(t)
#> [1] "INFO [2024-10-21 07:31:18] 42"