appender_file | R Documentation |
Log messages are written to a file with basic log rotation: when
max number of lines or bytes is defined to be other than Inf
,
then the log file is renamed with a .1
suffix and a new log file
is created. The renaming happens recursively (eg logfile.1
renamed to logfile.2
) until the specified max_files
, then the
oldest file (logfile.{max_files-1}
) is deleted.
appender_file(
file,
append = TRUE,
max_lines = Inf,
max_bytes = Inf,
max_files = 1L
)
file |
path |
append |
boolean passed to |
max_lines |
numeric specifying the maximum number of lines allowed in a file before rotating |
max_bytes |
numeric specifying the maximum number of bytes allowed in a file before rotating |
max_files |
integer specifying the maximum number of files to be used in rotation |
function taking lines
argument
Other log_appenders:
appender_async()
,
appender_console()
,
appender_kinesis()
,
appender_pushbullet()
,
appender_slack()
,
appender_stdout()
,
appender_syslog()
,
appender_tee()
,
appender_telegram()
## ##########################################################################
## simple example logging to a file
t <- tempfile()
log_appender(appender_file(t))
for (i in 1:25) log_info(i)
readLines(t)
## ##########################################################################
## more complex example of logging to file
## rotated after every 3rd line up to max 5 files
## create a folder storing the log files
t <- tempfile()
dir.create(t)
f <- file.path(t, "log")
## define the file logger with log rotation enabled
log_appender(appender_file(f, max_lines = 3, max_files = 5L))
## enable internal logging to see what's actually happening in the logrotate steps
log_threshold(TRACE, namespace = ".logger")
## log 25 messages
for (i in 1:25) log_info(i)
## see what was logged
lapply(list.files(t, full.names = TRUE), function(t) {
cat("\n##", t, "\n")
cat(readLines(t), sep = "\n")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.