Debian Codegraph @

man/print.LogEvent.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/LogEvent.R
3 \name{print.LogEvent}
4 \alias{print.LogEvent}
5 \alias{format.LogEvent}
6 \title{Print or Format Logging Data}
7 \usage{
8 \method{print}{LogEvent}(
9 x,
10 fmt = "\%L [\%t] \%m \%f",
11 timestamp_fmt = "\%Y-\%m-\%d \%H:\%M:\%S",
12 colors = getOption("lgr.colors"),
13 log_levels = getOption("lgr.log_levels"),
14 pad_levels = "right",
15 excluded_fields = NULL,
16 ...
17 )
18
19 \method{format}{LogEvent}(
20 x,
21 fmt = "\%L [\%t] \%m \%f",
22 timestamp_fmt = "\%Y-\%m-\%d \%H:\%M:\%S",
23 colors = NULL,
24 log_levels = getOption("lgr.log_levels"),
25 pad_levels = "right",
26 excluded_fields = NULL,
27 ...
28 )
29 }
30 \arguments{
31 \item{x}{a \link{LogEvent}}
32
33 \item{fmt}{A \code{character} scalar that may contain any of the tokens listed
34 bellow in the section Format Tokens.}
35
36 \item{timestamp_fmt}{see \code{\link[=format.POSIXct]{format.POSIXct()}}}
37
38 \item{colors}{A \code{list} of \code{functions} that will be used to color the
39 log levels (likely from \link[crayon:crayon]{crayon::crayon}).}
40
41 \item{log_levels}{named \code{integer} vector of valid log levels}
42
43 \item{pad_levels}{\code{right}, \code{left} or \code{NULL}. Whether or not to pad the log
44 level names to the same width on the left or right side, or not at all.}
45
46 \item{excluded_fields}{a \code{character} vector of fields to exclude from \verb{\%j} and
47 \verb{\%f}}
48
49 \item{...}{ignored}
50 }
51 \value{
52 \code{x} for \code{print()} and a \code{character} scalar for \code{format()}
53 }
54 \description{
55 Print or Format Logging Data
56 }
57 \section{Format Tokens}{
58
59 \describe{
60 \item{\verb{\%t}}{The timestamp of the message, formatted according to
61 \code{timestamp_fmt})}
62 \item{\verb{\%l}}{the log level, lowercase \code{character} representation}
63 \item{\verb{\%L}}{the log level, uppercase \code{character} representation}
64 \item{\verb{\%k}}{the log level, first letter of lowercase \code{character} representation}
65 \item{\verb{\%K}}{the log level, first letter of uppercase \code{character} representation}
66 \item{\verb{\%n}}{the log level, \code{integer} representation}
67 \item{\verb{\%g}}{the name of the logger}
68 \item{\verb{\%p}}{the PID (process ID). Useful when logging code that uses
69 multiple threads.}
70 \item{\verb{\%c}}{the calling function}
71 \item{\verb{\%m}}{the log message}
72 \item{\verb{\%r}}{the raw log message (without string interpolation)}
73 \item{\verb{\%f}}{all custom fields of \code{x} in a pseudo-JSON like format that is
74 optimized for human readability and console output}
75 \item{\verb{\%j}}{all custom fields of \code{x} in proper JSON. This requires that you
76 have \strong{jsonlite} installed and does not support colors as opposed to
77 \verb{\%f}
78 }
79 }
80 }
81
82 \examples{
83 # standard fields can be printed using special tokens
84 x <- LogEvent$new(
85 level = 300, msg = "a test event", caller = "testfun()", logger = lgr
86 )
87 print(x)
88 print(x, fmt = c("\%t (\%p) \%c: \%n - \%m"))
89 print(x, colors = NULL)
90
91 # custom values
92 y <- LogEvent$new(
93 level = 300, msg = "a gps track", logger = lgr,
94 waypoints = 10, location = "Austria"
95 )
96
97 # default output with \%f
98 print(y)
99
100 # proper JSON output with \%j
101 if (requireNamespace("jsonlite")){
102 print(y, fmt = "\%L [\%t] \%m \%j")
103 }
104
105 }