Learn R Programming

lgr (version 0.3.4)

AppenderFileRotating: Log to a rotating file

Description

An extension of AppenderFile that rotates logfiles based on certain conditions. Please refer to the documentation of rotor::rotate() for the meanings of the extra arguments

Arguments

Usage

x <- AppenderFileRotating$new(file, threshold = NA_integer_, layout =
  LayoutFormat$new(), filters = NULL, size = Inf, max_backups = Inf,
  compression = FALSE, backup_dir = dirname(file), create_file = TRUE)

x <- AppenderFileRotatingDate$new(file, threshold = NA_integer_, layout = LayoutFormat$new(), filters = NULL, age = Inf, size = -1, max_backups = Inf, compression = FALSE, backup_dir = dirname(file), fmt = "%Y-%m-%d", overwrite = FALSE, create_file = TRUE, cache_backups = TRUE)

x <- AppenderFileRotatingTime$new(file, threshold = NA_integer_, layout = LayoutFormat$new(), filters = NULL, age = Inf, size = -1, max_backups = Inf, compression = FALSE, backup_dir = dirname(file), fmt = "%Y-%m-%d--%H-%M-%S", overwrite = FALSE, create_file = TRUE, cache_backups = TRUE)

x$add_filter(filter, name = NULL) x$append(event) x$clone(deep = FALSE) x$filter(event) x$format(color = false, ...) x$format(color = FALSE, ...) x$prune(max_backups = self$max_backups) x$remove_filter(pos) x$rotate(force = FALSE, now = Sys.time()) x$rotate(force = FALSE) x$set_age(x) x$set_backup_dir(x) x$set_cache_backups(x) x$set_compression(x) x$set_create_file(x) x$set_file(file) x$set_filters(filters) x$set_fmt(x) x$set_layout(layout) x$set_max_backups(x) x$set_overwrite(x) x$set_size(x) x$set_threshold(level) x$show(threshold = NA_integer_, n = 20L)

x$age x$backup_dir x$backups x$cache_backups x$compression x$create_file x$destination x$file x$filters x$fmt x$layout x$max_backups x$overwrite x$size x$threshold

Fields

age, size, max_backups, fmt, overwrite, compression, backup_dir

Please see rotor::rotate() for the meaning of these arguments (fmt is passed on as format).

cache_backups, set_cache_backups(x)

TRUE or FALSE. If TRUE (the default) the list of backups is cached, if FALSE it is read from disk every time this appender triggers. Caching brings a significant speedup for checking whether to rotate or not based on the age of the last backup, but is only safe if there are no other programs/functions (except this appender) interacting with the backups.

backups

A data.frame containing information on path, file size, etc... on the available backups of file.

file, set_file(file)

character scalar. Path to the desired log file. If the file does not exist it will be created.

threshold, set_threshold(level)

character or integer scalar. The minimum log level that triggers this logger. See log_levels

layout, set_layout(layout)

a Layout that will be used for formatting the LogEvents passed to this Appender

destination

The output destination of the Appender in human-readable form (mainly for print output)

filters, set_filters(filters)

a list that may contain functions or any R object with a filter() method. These functions must have exactly one argument: event which will get passed the LogEvent when the Filterable's filter() method is invoked. If all of these functions evaluate to TRUE the LogEvent is passed on. Since LogEvents have reference semantics, filters can also be abused to modify them before they are passed on. Look at the source code of with_log_level() or with_log_value() for examples.

Creating a New Appender

New Appenders are instantiated with <AppenderSubclass>$new(). For the arguments to new() please refer to the section Fields. You can also modify those fields after the Appender has been created with setters in the form of appender$set_<fieldname>(value)

Methods

append(event)

Tell the Appender to process a LogEvent event. This method is usually not called by the user, but invoked by a Logger

filter(event)

Determine whether the LogEvent x should be passed on to Appenders (TRUE) or not (FALSE). See also the active binding filters

add_filter(filter, name = NULL), remove_filter(pos)

Add or remove a filter. When adding a filter an optional name can be specified. remove_filter() can remove by position or name (if one was specified)

See Also

LayoutFormat, LayoutJson, rotor::rotate()

Other Appenders: AppenderBuffer, AppenderConsole, AppenderDbi, AppenderFile, AppenderGmail, AppenderJson, AppenderPushbullet, AppenderRjdbc, AppenderSendmail, AppenderSyslog, AppenderTable, Appender