logger: Class to provide logging capabilities

Description Active bindings Methods Examples

Description

Class to provide logging capabilities

Class to provide logging capabilities

Active bindings

file

Set or get the file path of the logger

custom_sanitizer

get, replace or add custom sanitizer rules to the default sanitizer

default_sanitizer

get the default sanitizer rules

Methods

Public methods


Method new()

initialize a new logger with logger$new("file_path")

Usage
logger$new(file = NULL)
Arguments
file

file path to log file that already exists or should be created (optional)

Examples
##create a new log
log1 <- logger$new()
log2 <- logger$new("log1.log")

Method add()

add a log entry to the logging file

Usage
logger$add(log_lvl, log_msg, ..., echo = T)
Arguments
log_lvl

character string for the log level to record the log entry for

log_msg

log message to record

...

custom named values to record in the log

echo

Overriding echo = T argument

Examples
## add a log record
log1$add(log_lvl = "debug", log_msg = "some information")

Method warn()

add a log entry with "warn" as the log_lvl

Usage
logger$warn(log_msg, ..., echo = T)
Arguments
log_msg

log message to record

...

custom named values to record in the log

echo

Overriding echo = T argument


Method info()

add a log entry with "info" as the log_lvl

Usage
logger$info(log_msg, ..., echo = T)
Arguments
log_msg

log message to record

...

custom named values to record in the log

echo

Overriding echo = T argument


Method err()

add a log entry with "err" as the log_lvl

Usage
logger$err(log_msg, ..., echo = T)
Arguments
log_msg

log message to record

...

custom named values to record in the log

echo

Overriding echo = T argument


Method return_log()

return the log as a tibble

Usage
logger$return_log()

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## ------------------------------------------------
## Method `logger$new`
## ------------------------------------------------

##create a new log
log1 <- logger$new()
log2 <- logger$new("log1.log")

## ------------------------------------------------
## Method `logger$add`
## ------------------------------------------------

## add a log record
log1$add(log_lvl = "debug", log_msg = "some information")

jeydjey/logger documentation built on March 3, 2021, 3:33 p.m.