Delays executing the actual appender function to the future in a background process to avoid blocking the main R session
Source:R/appenders.R
appender_async.Rd
Delays executing the actual appender function to the future in a background process to avoid blocking the main R session
Usage
appender_async(
appender,
namespace = "async_logger",
init = function() log_info("Background process started")
)
Arguments
- appender
a
log_appender()
function with agenerator
attribute (TODO note not required, all fn will be passed if not)- namespace
logger
namespace to use for logging messages on starting up the background process- init
optional function to run in the background process that is useful to set up the environment required for logging, eg if the
appender
function requires some extra packages to be loaded or some environment variables to be set etc
See also
Other log_appenders:
appender_console()
,
appender_file()
,
appender_kinesis()
,
appender_pushbullet()
,
appender_slack()
,
appender_stdout()
,
appender_syslog()
,
appender_tee()
,
appender_telegram()
Examples
if (FALSE) { # \dontrun{
appender_file_slow <- function(file) {
force(file)
function(lines) {
Sys.sleep(1)
cat(lines, sep = "\n", file = file, append = TRUE)
}
}
## log what's happening in the background
log_threshold(TRACE, namespace = "async_logger")
log_appender(appender_console, namespace = "async_logger")
## start async appender
t <- tempfile()
log_info("Logging in the background to {t}")
## use async appender
log_appender(appender_async(appender_file_slow(file = t)))
log_info("Was this slow?")
system.time(for (i in 1:25) log_info(i))
readLines(t)
Sys.sleep(10)
readLines(t)
} # }