Debian Codegraph @

man/LayoutFormat.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/Layout.R
3 \name{LayoutFormat}
4 \alias{LayoutFormat}
5 \title{Format Log Events as Text}
6 \description{
7 Format Log Events as Text
8
9 Format Log Events as Text
10 }
11 \details{
12 Format a \link{LogEvent} as human readable text using \code{\link[=format.LogEvent]{format.LogEvent()}}, which
13 provides a quick and easy way to customize log messages. If you need
14 more control and flexibility, consider using \link{LayoutGlue} instead.
15
16 see Fields
17
18 see Fields
19
20 see Fields
21
22 see Fields
23
24 Convert Layout to a \code{character} string
25 Read a log file written using LayoutFormat
26 }
27 \section{Format Tokens}{
28
29 This is the same list of format tokens as for \code{\link[=format.LogEvent]{format.LogEvent()}}
30
31
32 \describe{
33 \item{\verb{\%t}}{The timestamp of the message, formatted according to
34 \code{timestamp_fmt})}
35 \item{\verb{\%l}}{the log level, lowercase \code{character} representation}
36 \item{\verb{\%L}}{the log level, uppercase \code{character} representation}
37 \item{\verb{\%k}}{the log level, first letter of lowercase \code{character} representation}
38 \item{\verb{\%K}}{the log level, first letter of uppercase \code{character} representation}
39 \item{\verb{\%n}}{the log level, \code{integer} representation}
40 \item{\verb{\%g}}{the name of the logger}
41 \item{\verb{\%p}}{the PID (process ID). Useful when logging code that uses
42 multiple threads.}
43 \item{\verb{\%c}}{the calling function}
44 \item{\verb{\%m}}{the log message}
45 \item{\verb{\%r}}{the raw log message (without string interpolation)}
46 \item{\verb{\%f}}{all custom fields of \code{x} in a pseudo-JSON like format that is
47 optimized for human readability and console output}
48 \item{\verb{\%j}}{all custom fields of \code{x} in proper JSON. This requires that you
49 have \strong{jsonlite} installed and does not support colors as opposed to
50 \verb{\%f}
51 }
52 }
53 }
54
55 \examples{
56 # setup a dummy LogEvent
57 event <- LogEvent$new(
58 logger = Logger$new("dummy logger"),
59 level = 200,
60 timestamp = Sys.time(),
61 caller = NA_character_,
62 msg = "a test message"
63 )
64 lo <- LayoutFormat$new()
65 lo$format_event(event)
66 }
67 \seealso{
68 Other Layouts:
69 \code{\link{Layout}},
70 \code{\link{LayoutGlue}},
71 \code{\link{LayoutJson}}
72 }
73 \concept{Layouts}
74 \section{Super class}{
75 \code{\link[lgr:Layout]{lgr::Layout}} -> \code{LayoutFormat}
76 }
77 \section{Active bindings}{
78 \if{html}{\out{<div class="r6-active-bindings">}}
79 \describe{
80 \item{\code{fmt}}{a \code{character} scalar containing format tokens. See \code{\link[=format.LogEvent]{format.LogEvent()}}.}
81
82 \item{\code{timestamp_fmt}}{a \code{character} scalar. See \code{\link[base:strptime]{base::format.POSIXct()}}.}
83
84 \item{\code{colors}}{a named \code{list} of functions (like the ones provided by
85 the package \pkg{crayon}) passed on on \code{\link[=format.LogEvent]{format.LogEvent()}}.}
86
87 \item{\code{pad_levels}}{\code{"right"}, \code{"left"} or \code{NULL}. See \code{\link[=format.LogEvent]{format.LogEvent()}}.}
88 }
89 \if{html}{\out{</div>}}
90 }
91 \section{Methods}{
92 \subsection{Public methods}{
93 \itemize{
94 \item \href{#method-LayoutFormat-new}{\code{LayoutFormat$new()}}
95 \item \href{#method-LayoutFormat-format_event}{\code{LayoutFormat$format_event()}}
96 \item \href{#method-LayoutFormat-set_fmt}{\code{LayoutFormat$set_fmt()}}
97 \item \href{#method-LayoutFormat-set_timestamp_fmt}{\code{LayoutFormat$set_timestamp_fmt()}}
98 \item \href{#method-LayoutFormat-set_colors}{\code{LayoutFormat$set_colors()}}
99 \item \href{#method-LayoutFormat-set_pad_levels}{\code{LayoutFormat$set_pad_levels()}}
100 \item \href{#method-LayoutFormat-toString}{\code{LayoutFormat$toString()}}
101 \item \href{#method-LayoutFormat-read}{\code{LayoutFormat$read()}}
102 \item \href{#method-LayoutFormat-clone}{\code{LayoutFormat$clone()}}
103 }
104 }
105 \if{html}{\out{
106 <details open><summary>Inherited methods</summary>
107 <ul>
108 <li><span class="pkg-link" data-pkg="lgr" data-topic="Layout" data-id="set_excluded_fields"><a href='../../lgr/html/Layout.html#method-Layout-set_excluded_fields'><code>lgr::Layout$set_excluded_fields()</code></a></span></li>
109 </ul>
110 </details>
111 }}
112 \if{html}{\out{<hr>}}
113 \if{html}{\out{<a id="method-LayoutFormat-new"></a>}}
114 \if{latex}{\out{\hypertarget{method-LayoutFormat-new}{}}}
115 \subsection{Method \code{new()}}{
116 \subsection{Usage}{
117 \if{html}{\out{<div class="r">}}\preformatted{LayoutFormat$new(
118 fmt = "\%L [\%t] \%m \%j",
119 timestamp_fmt = "\%Y-\%m-\%d \%H:\%M:\%OS3",
120 colors = NULL,
121 pad_levels = "right",
122 excluded_fields = NULL
123 )}\if{html}{\out{</div>}}
124 }
125
126 }
127 \if{html}{\out{<hr>}}
128 \if{html}{\out{<a id="method-LayoutFormat-format_event"></a>}}
129 \if{latex}{\out{\hypertarget{method-LayoutFormat-format_event}{}}}
130 \subsection{Method \code{format_event()}}{
131 Format a LogEvent
132 \subsection{Usage}{
133 \if{html}{\out{<div class="r">}}\preformatted{LayoutFormat$format_event(event)}\if{html}{\out{</div>}}
134 }
135
136 \subsection{Arguments}{
137 \if{html}{\out{<div class="arguments">}}
138 \describe{
139 \item{\code{event}}{a \link{LogEvent}}
140 }
141 \if{html}{\out{</div>}}
142 }
143 }
144 \if{html}{\out{<hr>}}
145 \if{html}{\out{<a id="method-LayoutFormat-set_fmt"></a>}}
146 \if{latex}{\out{\hypertarget{method-LayoutFormat-set_fmt}{}}}
147 \subsection{Method \code{set_fmt()}}{
148 \subsection{Usage}{
149 \if{html}{\out{<div class="r">}}\preformatted{LayoutFormat$set_fmt(x)}\if{html}{\out{</div>}}
150 }
151
152 }
153 \if{html}{\out{<hr>}}
154 \if{html}{\out{<a id="method-LayoutFormat-set_timestamp_fmt"></a>}}
155 \if{latex}{\out{\hypertarget{method-LayoutFormat-set_timestamp_fmt}{}}}
156 \subsection{Method \code{set_timestamp_fmt()}}{
157 \subsection{Usage}{
158 \if{html}{\out{<div class="r">}}\preformatted{LayoutFormat$set_timestamp_fmt(x)}\if{html}{\out{</div>}}
159 }
160
161 }
162 \if{html}{\out{<hr>}}
163 \if{html}{\out{<a id="method-LayoutFormat-set_colors"></a>}}
164 \if{latex}{\out{\hypertarget{method-LayoutFormat-set_colors}{}}}
165 \subsection{Method \code{set_colors()}}{
166 \subsection{Usage}{
167 \if{html}{\out{<div class="r">}}\preformatted{LayoutFormat$set_colors(x)}\if{html}{\out{</div>}}
168 }
169
170 }
171 \if{html}{\out{<hr>}}
172 \if{html}{\out{<a id="method-LayoutFormat-set_pad_levels"></a>}}
173 \if{latex}{\out{\hypertarget{method-LayoutFormat-set_pad_levels}{}}}
174 \subsection{Method \code{set_pad_levels()}}{
175 \subsection{Usage}{
176 \if{html}{\out{<div class="r">}}\preformatted{LayoutFormat$set_pad_levels(x)}\if{html}{\out{</div>}}
177 }
178
179 }
180 \if{html}{\out{<hr>}}
181 \if{html}{\out{<a id="method-LayoutFormat-toString"></a>}}
182 \if{latex}{\out{\hypertarget{method-LayoutFormat-toString}{}}}
183 \subsection{Method \code{toString()}}{
184 \subsection{Usage}{
185 \if{html}{\out{<div class="r">}}\preformatted{LayoutFormat$toString()}\if{html}{\out{</div>}}
186 }
187
188 }
189 \if{html}{\out{<hr>}}
190 \if{html}{\out{<a id="method-LayoutFormat-read"></a>}}
191 \if{latex}{\out{\hypertarget{method-LayoutFormat-read}{}}}
192 \subsection{Method \code{read()}}{
193 \subsection{Usage}{
194 \if{html}{\out{<div class="r">}}\preformatted{LayoutFormat$read(file, threshold = NA_integer_, n = 20L)}\if{html}{\out{</div>}}
195 }
196
197 \subsection{Arguments}{
198 \if{html}{\out{<div class="arguments">}}
199 \describe{
200 \item{\code{threshold}}{a \code{character} or \code{integer} threshold}
201
202 \item{\code{n}}{number of log entries to display}
203 }
204 \if{html}{\out{</div>}}
205 }
206 }
207 \if{html}{\out{<hr>}}
208 \if{html}{\out{<a id="method-LayoutFormat-clone"></a>}}
209 \if{latex}{\out{\hypertarget{method-LayoutFormat-clone}{}}}
210 \subsection{Method \code{clone()}}{
211 The objects of this class are cloneable with this method.
212 \subsection{Usage}{
213 \if{html}{\out{<div class="r">}}\preformatted{LayoutFormat$clone(deep = FALSE)}\if{html}{\out{</div>}}
214 }
215
216 \subsection{Arguments}{
217 \if{html}{\out{<div class="arguments">}}
218 \describe{
219 \item{\code{deep}}{Whether to make a deep clone.}
220 }
221 \if{html}{\out{</div>}}
222 }
223 }
224 }