LayoutJson {lgr} | R Documentation |
Format LogEvents as JSON
Description
A format for formatting LogEvents as jsonlines log files. This provides a nice balance between human- an machine-readability.
Super class
lgr::Layout
-> LayoutJson
Active bindings
toJSON_args
a list of values passed on to
jsonlite::toJSON()
timestamp_fmt
Used by
$format_event()
to format timestamps.
Methods
Public methods
Method new()
Usage
LayoutJson$new(toJSON_args = list(auto_unbox = TRUE), timestamp_fmt = NULL)
Method format_event()
Usage
LayoutJson$format_event(event)
Method set_toJSON_args()
Set arguments to pass on to jsonlite::toJSON()
Usage
LayoutJson$set_toJSON_args(x)
Arguments
x
a named
list
Method set_timestamp_fmt()
Set a format that this Layout will apply to timestamps.
Usage
LayoutJson$set_timestamp_fmt(x)
Arguments
x
-
-
NULL
(the default): formatting of the timestamp is left tojsonlite::toJSON()
, a
character
scalar as forformat.POSIXct()
, ora
function
that returns a vector of the same length as its (POSIXct) input. The returned vector can be of any type supported byjsonlite::toJSON()
, but should usually becharacter
.
-
Method toString()
Usage
LayoutJson$toString()
Method parse()
Usage
LayoutJson$parse(file)
Method read()
Usage
LayoutJson$read(file, threshold = NA_integer_, n = 20L)
Method clone()
The objects of this class are cloneable with this method.
Usage
LayoutJson$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
read_json_lines()
, https://jsonlines.org/
Other Layouts:
LayoutFormat
,
LayoutGlue
,
Layout
Examples
# setup a dummy LogEvent
event <- LogEvent$new(
logger = Logger$new("dummy logger"),
level = 200,
timestamp = Sys.time(),
caller = NA_character_,
msg = "a test message",
custom_field = "LayoutJson can handle arbitrary fields"
)
# Default settings show all event fals
lo <- LayoutJson$new()
lo$format_event(event)