| LayoutJson | R Documentation |
A format for formatting LogEvents as jsonlines log files. This provides a nice balance between human- an machine-readability.
lgr::Layout -> LayoutJson
toJSON_argsa list
timestamp_fmta character scalar or a function that accepts a POSIXct
as its single argument
transform_eventa function that accepts a LogEvent as its single argument
transform_event_namesa named character vector or a function that accepts a
character vector of field names as its single argument.
new()Creates a new instance of this R6 class.
LayoutJson$new( toJSON_args = list(auto_unbox = TRUE), timestamp_fmt = NULL, transform_event = function(event) event[["values"]], transform_event_names = NULL, excluded_fields = "rawMsg" )
toJSON_argsa list of arguments passed to jsonlite::toJSON(),
timestamp_fmtFormat to be applied to the timestamp. This is
applied after transform_event but before transform_event_names
NULL: formatting of the timestamp is left to jsonlite::toJSON(),
a character scalar as for format.POSIXct(), or
a function that returns a vector of the same length as its
(POSIXct) input. The returned vector can be of any type
supported by jsonlite::toJSON().
transform_eventa function with a single argument that
takes a LogEvent object and returns a list of values.
transform_event_namesNULL: don't process names
a named character vector of the format new_name = old_name
or a function with a single mandatory argument that accepts a
character vector of field names. Applied after transform_event.
excluded_fieldsA character vector of field names to exclude
from the final output. Applied after transform_event_names.
format_event()LayoutJson$format_event(event)
set_toJSON_args()LayoutJson$set_toJSON_args(x)
xa list
set_timestamp_fmt()LayoutJson$set_timestamp_fmt(x)
xa character scalar or a function that accepts a POSIXct
as its single argument
set_transform_event()LayoutJson$set_transform_event(x)
xa function that accepts a LogEvent as its single argument
set_transform_event_names()LayoutJson$set_transform_event_names(x)
xa named character vector or a function that accepts a
character vector of field names as its single argument.
toString()Represent the LayoutJson class as a string
LayoutJson$toString()
parse()Read and parse file written using this Layout
This can be used by the $data active binding of an Appender
LayoutJson$parse(file)
filecharacter scalar: path to a file
read()Read a file written using this Layout (without parsing)
This can be used by the $show() method of an Appender
LayoutJson$read(file, threshold = NA_integer_, n = 20L)
filecharacter scalar: path to a file
thresholdcharacter Minimum log level to show. Requires parsing
of the log file (but will still display unparsed output)
ninteger number of lines to show
clone()The objects of this class are cloneable with this method.
LayoutJson$clone(deep = FALSE)
deepWhether to make a deep clone.
read_json_lines(), https://jsonlines.org/
Other Layouts:
Layout,
LayoutFormat,
LayoutGlue
# 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"
)
lo <- LayoutJson$new()
lo$format_event(event)
lo <- LayoutJson$new(
transform_event_names = toupper,
excluded_fields = c("RAWMSG", "CALLER"))
lo$format_event(event)
lo <- LayoutJson$new(
transform_event = function(e) {
values <- e$values
values$msg <- toupper(values$msg)
values
},
timestamp_fmt = "%a %b %d %H:%M:%S %Y",
excluded_fields = c("RAWMSG", "CALLER"))
lo$format_event(event)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.