An event_list is a class for list()
s whose only elements are LogEvents.
This structure is occasionally used internally in lgr (for example by
AppenderBuffer) and can be useful for developers that want to write
their own Appenders.
Usage
event_list(...)
as_event_list(x, ...)
# S3 method for class 'list'
as_event_list(x, ..., scalarize = FALSE)
# S3 method for class 'LogEvent'
as_event_list(x, ..., scalarize = FALSE)
# S3 method for class 'data.frame'
as_event_list(x, na.rm = TRUE, ...)
as.data.table.event_list(x, na.rm = TRUE)
# S3 method for class 'event_list'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
stringsAsFactors = FALSE,
na.rm = TRUE,
...
)
Arguments
- ...
for
event
elements to be added to the list, for theas_*()
functions parameters passed on to methods.- x
any
R
object- scalarize
logical
scalar. Turn LogEvents with non-scalarmsg
field into separate log events- na.rm
remove
NA
values before coercing a data.frame to anevent_list()
.- row.names
NULL
or a character vector giving the row names for the data frame. Missing values are not allowed.- optional
currently ignored and only included for compatibility.
- stringsAsFactors
logical
scalar: shouldcharacter
vectors be converted to factors? Defaults toFALSE
(as opposed tobase::as.data.frame()
) and is only included for compatibility.
Value
an event_list()
and as_event_list()
return a flat list
of LogEvents. Nested lists get automatically flattened.
as.data.frame
and as.data.table
return a data.frame
or data.table
respectively
Details
For convenience, as.data.frame()
and as.data.table()
methods
exist for event lists.
See also
Other docs relevant for extending lgr:
LogEvent
,
as_LogEvent()
,
standardize_threshold()
Examples
e <- LogEvent$new(level = 300, msg = "a", logger = lgr)
as_event_list(e)
#> [[1]]
#> WARN [2025-04-14 20:58:49] a
#>
#> attr(,"class")
#> [1] "event_list" "list"
as_event_list(c(e, e))
#> [[1]]
#> WARN [2025-04-14 20:58:49] a
#>
#> [[2]]
#> WARN [2025-04-14 20:58:49] a
#>
#> attr(,"class")
#> [1] "event_list" "list"
# nested lists get automatically unnested
as_event_list(c(e, list(nested_event = e)))
#> [[1]]
#> WARN [2025-04-14 20:58:49] a
#>
#> $nested_event
#> WARN [2025-04-14 20:58:49] a
#>
#> attr(,"class")
#> [1] "event_list" "list"
# scalarize = TRUE "unpacks" events with vector log messages
e <- LogEvent$new(level = 300, msg = c("A", "B"), logger = lgr)
as_event_list(e, scalarize = FALSE)
#> [[1]]
#> WARN [2025-04-14 20:58:49] A
#> WARN [2025-04-14 20:58:49] B
#>
#> attr(,"class")
#> [1] "event_list" "list"
as_event_list(e, scalarize = TRUE)
#> [[1]]
#> WARN [2025-04-14 20:58:49] A
#>
#> [[2]]
#> WARN [2025-04-14 20:58:49] B
#>
#> attr(,"class")
#> [1] "event_list" "list"