
Last chance! 50% off unlimited learning
Sale ends in
A LogEvent
is a single unit of data that should be logged. LogEvents
are
usually created by a Logger, and then processed by Appenders.
x <- LogEvent$new(logger, level = 400, timestamp = Sys.time(), caller = NA, msg = NA, ...)x$clone(deep = FALSE)
x$.logger x$caller x$level x$level_name x$logger x$msg x$timestamp x$values
The arguments to LogEvent$new()
directly translate to the fields stored in
the LogEvent:
level
integer
: the log_level / priority of the LogEvent
timestamp
POSIXct
the time when then the
LogEvent was created
caller
character
. The name of the calling function
msg
character
. A message
logger
character
scalar. Name of the Logger that created the
event (.logger$full_name
)
user
character
scalar. User as set for the Logger
that created this event (.logger$user
)
.logger
a Logger
. A reference to the Logger that created the
event
...
All named arguments in ...
will be added to the LogEvent
as custom fields. You can store arbitrary R objects in LogEvents
this way, but not all Appenders will support them.
See AppenderJson for
an Appender that supports custom fields quite naturally.
Usually the above values will be scalars, but (except for "logger"
) they
can also be vectors if they are all of the same length (or scalars that will
be recycled). In this case the event will be treated by the Appenders and
Layouts as if several separate events.
LogEvents contain some some active bindings that make it easier to retrieve commonly used values.
level_name
character
: the log_level / priority of the
LogEvent labelled according to getOption("lgr.log_levels")
values
list
: All values stored in the LogEvent (including
all custom fields, but not including event$logger
)
logger_name
character
scalar: The name of the Logger that
created this event, equivalent to event$logger$name
)
logger_user
character
scalar: The user of the Logger that
created this event, equivalent to event$logger_user
)
# NOT RUN {
l <- Logger$new("dummy logger", appenders = NULL)
l$error("foo bar")
# The last LogEvent produced by a Logger is stored in the last_event field
l$last_event # formatted by default
l$last_event$values # values stored in the event
# Also contains the Logger that created it as .logger
l$last_event$logger
# equivalent to
l$last_event$.logger$name
# This is really a reference to the complete Logger, so the following is
# possible (though nonsensical)
l$last_event$.logger$last_event$msg
identical(l, l$last_event$.logger)
# }
Run the code above in your browser using DataLab