Learn R Programming

log4r (version 0.4.4)

loglevel: Logging levels

Description

Functions for handling logging levels. With each log entry, a logging level is associated that indicate its severity -- debugging output, informational output, warning message, error message or fatal error. Each logger only prints log entries where the log level is equal or above its threshold.

Usage

loglevel(i)

is.loglevel(x, ...)

as.loglevel(i)

# S3 method for loglevel print(x, ...)

# S3 method for loglevel as.numeric(x, ...)

# S3 method for loglevel as.character(x, ...)

available.loglevels()

verbosity(v)

Value

An object of class "loglevel"

Arguments

i

An integer from the set 1..5. Otherwise it will be modified sensibly to fit in that range. Alternatively, a named logging level (one of "DEBUG", "INFO", "WARN", "ERROR", or "FATAL").

x

An object of class "loglevel"

...

Unused

v

A verbosity level from the set 5..1. For historical reasons, they do not match the log levels; a verbosity level of 1 corresponds to a logging level of 5, 2 corresponds to 4, etc.

Details

To specify a logging level, use a character value, e.g. "WARN", or an integer between 1 and 5. The function available.levels lists all possible logging levels.

Examples

Run this code
loglevel(2) == loglevel("INFO")
loglevel("WARN") < loglevel("ERROR")
loglevel(-1)
try(loglevel("UNDEFINED"))
is.loglevel("DEBUG")
is.loglevel(loglevel("DEBUG"))
as.numeric(loglevel("FATAL"))
available.loglevels()

if (FALSE) {
library(optparse)
library(log4r)

optlist <- list(make_option(c('-v', '--verbosity-level'),
  type = "integer",
  dest = "verbosity",
  default = 1,
  help = "Verbosity threshold (5=DEBUG, 4=INFO 3=WARN, 2=ERROR, 1=FATAL)"))

optparser <- OptionParser(option_list=optlist)
opt <- parse_args(optparser)

my.logger <- create.logger(logfile = "", level = verbosity(opt$verbosity))

fatal(my.logger, "Fatal message")
error(my.logger, "Error message")
warn(my.logger, "Warning message")
info(my.logger, "Informational message")
debug(my.logger, "Debugging message")
}

Run the code above in your browser using DataLab