Creates Logger object which can be used for logging with different level of verbosity. Log messages are in JSON format.

See also

Methods

Public methods


Method new()

Creates Logger object.

Usage

Logger$new(
  level = c("info", "fatal", "error", "warn", "debug", "trace", "off", "all"),
  name = "ROOT",
  printer = NULL
)

Arguments

level

Log level. Allowed values: info, fatal, error, warn, debug, trace, off, all.

name

Logger name.

printer

Logger with sink defined by printer function. It should have signature function(timestamp, level, logger_name, pid, message). By default when printer = NULL logger writes message in JSON format to stdout.


Method set_name()

Sets logger name.

Usage

Logger$set_name(name = "ROOT")

Arguments

name

Logger name.


Method set_log_level()

Sets log level.

Usage

Logger$set_log_level(
  level = c("info", "fatal", "error", "warn", "debug", "trace", "off", "all")
)

Arguments

level

Log level. Allowed values: info, fatal, error, warn, debug, trace, off, all.


Method set_printer()

Sets function which defines how to print logs.

Usage

Logger$set_printer(FUN = NULL)

Arguments

FUN

Printer function. Should be a function with 6 formal arguments: timestamp, level, logger_name, pid, message.


Method trace()

Write trace message.

Usage

Logger$trace(msg, ...)

Arguments

msg

Log message.

...

Additionals params.


Method debug()

Write debug message.

Usage

Logger$debug(msg, ...)

Arguments

msg

Log message.

...

Additionals params.


Method info()

Write information message.

Usage

Logger$info(msg, ...)

Arguments

msg

Log message.

...

Additionals params.


Method warn()

Write warning message.

Usage

Logger$warn(msg, ...)

Arguments

msg

Log message.

...

Additionals params.


Method error()

Write error message.

Usage

Logger$error(msg, ...)

Arguments

msg

Log message.

...

Additionals params.


Method fatal()

Write fatal error message.

Usage

Logger$fatal(msg, ...)

Arguments

msg

Log message.

...

Additionals params.


Method clone()

The objects of this class are cloneable with this method.

Usage

Logger$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# init logger
logger = Logger$new("info")
# write info message
logger$info("hello world")
# write extended log entry
logger$info("", context = list(message = "hello world", code = 0L))