Learn R Programming

lgr (version 0.3.4)

LayoutGlue: Format Log Events as Text via glue

Description

Format a LogEvent as human readable text using glue::glue. The function is evaluated in an environment in which it has access to all elements of the LogEvent (see examples). This is more flexible than LayoutFormat, but also more complex and slightly less performant.

Arguments

Usage

x <- LayoutGlue$new(fmt = "{pad_right(colorize_levels(toupper(level_name)), 5)}
  [{timestamp}] msg")

x$clone(deep = FALSE) x$format_event(event) x$set_colors(x) x$set_fmt(x) x$toString()

x$fmt

Creating a New LayoutGlue

A new LayoutGlue is instantiated with LayoutGlue$new(). It takes a single argument fmt that is passed on to glue::glue() for each LogEvent.

Fields

fmt

see glue::glue()

Methods

format_event(event)

format a LogEvent

See Also

lgr exports a number of formatting utility functions that are useful for layout glue: colorize_levels(), pad_left(), pad_right().

Other Layouts: LayoutDbi, LayoutFormat, LayoutJson, Layout

Examples

Run this code
# NOT RUN {
lg <- get_logger("test")$
  set_appenders(AppenderConsole$new())$
  set_propagate(FALSE)

lg$appenders[[1]]$set_layout(LayoutGlue$new())
lg$fatal("test")


# All fields of the LogEvent are available, even custom ones
lg$appenders[[1]]$layout$set_fmt(
  "{logger$name} {level_name}({level}) {caller}: {toupper(msg)} {{custom: {custom}}}"
)
lg$fatal("test", custom = "foobar")
lg$config(NULL)  # reset logger config

# }

Run the code above in your browser using DataLab