Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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.

Super class

lgr::Layout -> LayoutGlue

Active bindings

fmt

A string that will be interpreted by glue::glue()

Methods

Public methods

Inherited methods

Method new()

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

Method format_event()

Usage
LayoutGlue$format_event(event)

Method set_fmt()

Usage
LayoutGlue$set_fmt(x)

Method set_colors()

Usage
LayoutGlue$set_colors(x)

Method toString()

Usage
LayoutGlue$toString()

Method clone()

The objects of this class are cloneable with this method.

Usage
LayoutGlue$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

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

Other Layouts: LayoutFormat, LayoutJson, Layout

Examples

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} {level_name}({level}) {caller}: {toupper(msg)} {{custom: {custom}}}"
)
lg$fatal("test", custom = "foobar")
lg$config(NULL)  # reset logger config

lgr

A Fully Featured Logging Framework

v0.4.2
MIT + file LICENSE
Authors
Stefan Fleck [aut, cre] (<https://orcid.org/0000-0003-3344-9851>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.