| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/utils-logging.R |
| 3 |
\name{suspend_logging} |
| 4 |
\alias{suspend_logging} |
| 5 |
\alias{unsuspend_logging} |
| 6 |
\alias{without_logging} |
| 7 |
\alias{with_logging} |
| 8 |
\title{Suspend All Logging} |
| 9 |
\usage{ |
| 10 |
suspend_logging() |
| 11 |
|
| 12 |
unsuspend_logging() |
| 13 |
|
| 14 |
without_logging(code) |
| 15 |
|
| 16 |
with_logging(code) |
| 17 |
} |
| 18 |
\arguments{ |
| 19 |
\item{code}{Any \R code} |
| 20 |
} |
| 21 |
\value{ |
| 22 |
\code{suspend_logging()} and \code{unsuspend_logging()} return \code{NULL} (invisibly), |
| 23 |
\code{without_logging()} and \code{with_logging()} returns whatever \code{code} returns. |
| 24 |
} |
| 25 |
\description{ |
| 26 |
Completely disable logging for all loggers. This is for example useful for |
| 27 |
automated test code. \code{suspend_logging()} globally disables all logging with |
| 28 |
lgr until \code{unsuspend_logging()} is invoked, while \code{without_logging()} and |
| 29 |
\code{with_logging()} temporarily disable/enable logging. |
| 30 |
} |
| 31 |
\examples{ |
| 32 |
lg <- get_logger("test") |
| 33 |
|
| 34 |
# temporarily disable logging |
| 35 |
lg$fatal("foo") |
| 36 |
without_logging({ |
| 37 |
lg$info("everything in this codeblock will be suppressed") |
| 38 |
lg$fatal("bar") |
| 39 |
}) |
| 40 |
|
| 41 |
# globally disable logging |
| 42 |
suspend_logging() |
| 43 |
lg$fatal("bar") |
| 44 |
with_logging(lg$fatal("foo")) # log anyways |
| 45 |
|
| 46 |
# globally enable logging again |
| 47 |
unsuspend_logging() |
| 48 |
lg$fatal("foo") |
| 49 |
} |