Debian Codegraph @

man/with_log_level.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/utils-logging.R
3 \name{with_log_level}
4 \alias{with_log_level}
5 \alias{with_log_value}
6 \title{Inject Values into Logging Calls}
7 \usage{
8 with_log_level(level, code, logger = lgr::lgr)
9
10 with_log_value(values, code, logger = lgr::lgr)
11 }
12 \arguments{
13 \item{level}{\code{integer} or \code{character} scalar: the desired log level}
14
15 \item{code}{Any \R code}
16
17 \item{logger}{a \link{Logger} or the name of one (see \code{\link[=get_logger]{get_logger()}}). Defaults
18 to the root logger (\code{lgr::lgr}).}
19
20 \item{values}{a named \code{list} of values to be injected into the logging calls}
21 }
22 \value{
23 whatever \code{code} would return
24 }
25 \description{
26 \code{with_log_level} temporarily overrides the log level of all \link{LogEvents}
27 created by target \link{Logger}.
28 }
29 \details{
30 These functions abuses lgr's filter mechanic to modify LogEvents in-place
31 before they passed on the Appenders. Use with care as they can
32 produce hard to reason about code.
33 }
34 \examples{
35 with_log_level("warn", {
36 lgr$info("More important than it seems")
37 lgr$fatal("Really not so bad")
38 })
39 with_log_value(
40 list(msg = "overriden msg"), {
41 lgr$info("bar")
42 lgr$fatal("FOO")
43 })
44 }