1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/logger.R
\name{handlers-management}
\alias{handlers-management}
\alias{addHandler}
\alias{removeHandler}
\title{Add a handler to or remove one from a logger.}
\usage{
addHandler(handler, ..., logger = "")
removeHandler(handler, logger = "")
}
\arguments{
\item{handler}{The name of the handler, or its action}
\item{...}{Extra parameters, to be stored in the handler list
\dots may contain extra parameters that will be passed to the handler
action. Some elements in the \dots will be interpreted here.}
\item{logger}{the name of the logger to which to attach the new handler,
defaults to the root logger.}
}
\description{
Use this function to maintain the list of handlers attached to a logger.\cr
\cr
\code{addHandler} and \code{removeHandler} are also offered as methods of the
\var{Logger} S4 class.
}
\details{
Handlers are implemented as environments. Within a logger a handler is
identified by its \var{name} and all handlers define at least the
three variables:
\describe{
\item{level}{all records at level lower than this are skipped.}
\item{formatter}{a function getting a record and returning a string}
\item{\code{action(msg, handler)}}{a function accepting two parameters: a
formatted log record and the handler itself. making the handler a
parameter of the action allows us to have reusable action functions.}
}
Being an environment, a handler may define as many variables as you
think you need. keep in mind the handler is passed to the action
function, which can check for existence and can use all variables that
the handler defines.
}
\examples{
logReset()
addHandler(writeToConsole)
names(getLogger()[["handlers"]])
loginfo("test")
removeHandler("writeToConsole")
logwarn("test")
}
|