Logger | R Documentation |
Creates Logger object which can be used for logging with different level of verbosity. Log messages are in JSON format.
new()
Creates Logger object.
Logger$new( level = c("info", "fatal", "error", "warn", "debug", "trace", "off", "all"), name = "ROOT", printer = NULL )
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
.
set_name()
Sets logger name.
Logger$set_name(name = "ROOT")
name
Logger name.
set_log_level()
Sets log level.
Logger$set_log_level( level = c("info", "fatal", "error", "warn", "debug", "trace", "off", "all") )
level
Log level. Allowed values: info, fatal, error, warn, debug, trace, off, all.
set_printer()
Sets function which defines how to print logs.
Logger$set_printer(FUN = NULL)
FUN
Printer function. Should be a function with 6 formal arguments: timestamp, level, logger_name, pid, message.
trace()
Write trace message.
Logger$trace(msg, ...)
msg
Log message.
...
Additionals params.
debug()
Write debug message.
Logger$debug(msg, ...)
msg
Log message.
...
Additionals params.
info()
Write information message.
Logger$info(msg, ...)
msg
Log message.
...
Additionals params.
warn()
Write warning message.
Logger$warn(msg, ...)
msg
Log message.
...
Additionals params.
error()
Write error message.
Logger$error(msg, ...)
msg
Log message.
...
Additionals params.
fatal()
Write fatal error message.
Logger$fatal(msg, ...)
msg
Log message.
...
Additionals params.
clone()
The objects of this class are cloneable with this method.
Logger$clone(deep = FALSE)
deep
Whether to make a deep clone.
lgr::Logger
# 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.