Debian Codegraph @

man/LogEvent.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/LogEvent.R
3 \name{LogEvent}
4 \alias{LogEvent}
5 \alias{LogEvents}
6 \title{LogEvents - The atomic unit of logging}
7 \description{
8 A \code{LogEvent} is a single unit of data that should be logged. \code{LogEvents} are
9 usually created by a \link{Logger}, and then processed by one more \link{Appenders}.
10 They do not need to be instantiated manually except for testing and
11 experimentation; however, if you plan on writing your own Appenders or
12 Layouts you need to understand LogEvents.
13 }
14 \examples{
15 lg <- get_logger("test")
16 lg$error("foo bar")
17
18 # The last LogEvent produced by a Logger is stored in its `last_event` field
19 lg$last_event # formatted console output
20 lg$last_event$values # values stored in the event
21
22 # Also contains the Logger that created it as .logger
23 lg$last_event$logger
24 # equivalent to
25 lg$last_event$.logger$name
26
27 # This is really a reference to the complete Logger, so the following is
28 # possible (though nonsensical)
29 lg$last_event$.logger$last_event$msg
30 identical(lg, lg$last_event$.logger)
31 lg$config(NULL) # reset logger config
32 }
33 \seealso{
34 \code{\link[=as.data.frame.LogEvent]{as.data.frame.LogEvent()}}
35
36 Other docs relevant for extending lgr:
37 \code{\link{as_LogEvent}()},
38 \code{\link{event_list}()},
39 \code{\link{standardize_threshold}()}
40 }
41 \concept{docs relevant for extending lgr}
42 \section{Public fields}{
43 \if{html}{\out{<div class="r6-fields">}}
44 \describe{
45 \item{\code{level}}{\code{integer}. The \link{log_level} / priority of the LogEvent. Use the
46 active binding \code{level_name} to get the \code{character} representation
47 instead.}
48
49 \item{\code{timestamp}}{\code{\link[base:DateTimeClasses]{POSIXct}}. The time when then the
50 LogEvent was created.}
51
52 \item{\code{caller}}{\code{character}. The name of the calling function.}
53
54 \item{\code{msg}}{\code{character}. The log message.}
55
56 \item{\code{.logger}}{\link{Logger}. A reference to the Logger that created the
57 event (equivalent to \code{get_logger(event$logger)}).}
58
59 \item{\code{rawMsg}}{\code{character}. The raw log message without string
60 interpolation.}
61 }
62 \if{html}{\out{</div>}}
63 }
64 \section{Active bindings}{
65 \if{html}{\out{<div class="r6-active-bindings">}}
66 \describe{
67 \item{\code{values}}{\code{list}. All values stored in the \code{LogEvent}, including
68 all \emph{custom fields}, but not including \code{event$.logger}.}
69
70 \item{\code{level_name}}{\code{character}. The \link{log_level} / priority of the LogEvent labelled
71 according to \code{getOption("lgr.log_levels")}}
72
73 \item{\code{logger}}{\code{character} scalar. The name of the Logger that
74 created this event, equivalent to \code{event$.logger$name})}
75 }
76 \if{html}{\out{</div>}}
77 }
78 \section{Methods}{
79 \subsection{Public methods}{
80 \itemize{
81 \item \href{#method-LogEvent-new}{\code{LogEvent$new()}}
82 \item \href{#method-LogEvent-clone}{\code{LogEvent$clone()}}
83 }
84 }
85 \if{html}{\out{<hr>}}
86 \if{html}{\out{<a id="method-LogEvent-new"></a>}}
87 \if{latex}{\out{\hypertarget{method-LogEvent-new}{}}}
88 \subsection{Method \code{new()}}{
89 The arguments to \code{LogEvent$new()} directly translate to the fields stored
90 in the \code{LogEvent}. Usually these values will be scalars, but (except for
91 \code{"logger"}) they can also be vectors if they are all of the same length (or
92 scalars that will be recycled). In this case the event will be treated by
93 the \link{Appenders} and \link{Layouts} as if several separate events.
94 \subsection{Usage}{
95 \if{html}{\out{<div class="r">}}\preformatted{LogEvent$new(
96 logger,
97 level = 400,
98 timestamp = Sys.time(),
99 caller = NA,
100 msg = NA,
101 rawMsg = msg,
102 ...
103 )}\if{html}{\out{</div>}}
104 }
105
106 \subsection{Arguments}{
107 \if{html}{\out{<div class="arguments">}}
108 \describe{
109 \item{\code{logger, level, timestamp, caller, msg}}{see \strong{Public fields}.}
110
111 \item{\code{...}}{All named arguments in \code{...} will be added to the LogEvent
112 as \strong{custom fields}. You can store arbitrary \R objects in LogEvents
113 this way, but not all Appenders will support them. See \link{AppenderJson} for}
114 }
115 \if{html}{\out{</div>}}
116 }
117 }
118 \if{html}{\out{<hr>}}
119 \if{html}{\out{<a id="method-LogEvent-clone"></a>}}
120 \if{latex}{\out{\hypertarget{method-LogEvent-clone}{}}}
121 \subsection{Method \code{clone()}}{
122 The objects of this class are cloneable with this method.
123 \subsection{Usage}{
124 \if{html}{\out{<div class="r">}}\preformatted{LogEvent$clone(deep = FALSE)}\if{html}{\out{</div>}}
125 }
126
127 \subsection{Arguments}{
128 \if{html}{\out{<div class="arguments">}}
129 \describe{
130 \item{\code{deep}}{Whether to make a deep clone.}
131 }
132 \if{html}{\out{</div>}}
133 }
134 }
135 }