Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

with_log_level

Inject Values into Logging Calls


Description

with_log_level temporarily overrides the log level of all LogEvents created by target Logger.

Usage

with_log_level(level, code, logger = lgr::lgr)

with_log_value(values, code, logger = lgr::lgr)

Arguments

level

integer or character scalar: the desired log level

code

Any R code

logger

a Logger or the name of one (see get_logger()). Defaults to the root logger (lgr::lgr).

values

a named list of values to be injected into the logging calls

Details

These functions abuses lgr's filter mechanic to modify LogEvents in-place before they passed on the Appenders. Use with care as they can produce hard to reason about code.

Value

whatever code would return

Examples

with_log_level("warn", {
  lgr$info("More important than it seems")
  lgr$fatal("Really not so bad")
})
with_log_value(
  list(msg = "overriden msg"),  {
  lgr$info("bar")
  lgr$fatal("FOO")
})

lgr

A Fully Featured Logging Framework

v0.4.2
MIT + file LICENSE
Authors
Stefan Fleck [aut, cre] (<https://orcid.org/0000-0003-3344-9851>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.