Learn R Programming

loggit2 (version 2.3.1)

with_loggit: Log any expressions

Description

Log code without having to explicitly use the loggit2 handlers. This is particularly useful for code that cannot be customized, e.g. from third-party packages.

Usage

with_loggit(
  exp,
  logfile = get_logfile(),
  echo = get_echo(),
  log_level = get_log_level()
)

Value

The result of the expression.

Arguments

exp

An expression to evaluate.

logfile

Path of log file to write to.

echo

Should the log entry (json) be echoed to stdout as well?

log_level

The log level to use.

Details

If loggit2 handlers are already used in the expression, this can lead to conditions being logged twice (in the same or different files).

Examples

Run this code
if (FALSE) {
 x <- with_loggit(5L + 5L)

 with_loggit(base::message("Test log message"))

 with_loggit(base::warning("Test log message"), echo = FALSE, logfile = "my_log.log")

 x <- with_loggit({
    y <- 5L
    base::message("Test log message")
    base::warning("Test log message")
    1L + y
 })
}

Run the code above in your browser using DataLab