flog.layout: Manage layouts within the 'futile.logger' sub-system

Description Arguments Usage Details Author(s) See Also Examples

Description

Provides functions for managing layouts. Typically 'flog.layout' is only used when manually creating a logging configuration.

Arguments

...

Used internally by lambda.r

Usage

# Get the layout function for the given logger
flog.layout(name) %::% character : Function
flog.layout(name='ROOT')

# Set the layout function for the given logger
flog.layout(fn, name='ROOT')

# Decorate log messages with a standard format
layout.simple(level, msg, ...)

# Generate log messages as JSON
layout.json(level, msg, ...)

# Decorate log messages using a custom format
layout.format(format, datetime.fmt="

# Show the value of a single variable layout.tracearg(level, msg, ...)

Details

Layouts are responsible for formatting messages so they are human-readable. Similar to an appender, a layout is assigned to a logger by calling flog.layout. The flog.layout function is used internally to get the registered layout function. It is kept visible so user-level introspection is possible.

layout.simple is a pre-defined layout function that prints messages in the following format:
LEVEL [timestamp] message

This is the default layout for the ROOT logger.

layout.format allows you to specify the format string to use in printing a message. The following tokens are available.

~l

Log level

~t

Timestamp

~n

Namespace

~f

The calling function

~m

The message

layout.json converts the message and any additional objects provided to a JSON structure. E.g.:

flog.info("Hello, world", cat='asdf')

yields something like

{"level":"INFO","timestamp":"2015-03-06 19:16:02 EST","message":"Hello, world","func":"(shell)","cat":["asdf"]}

layout.tracearg is a special layout that takes a variable and prints its name and contents.

Author(s)

Brian Lee Yung Rowe

See Also

flog.logger flog.appender

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Set the layout for 'my.package'
flog.layout(layout.simple, name='my.package')

# Update the ROOT logger to use a custom layout
layout <- layout.format('[~l] [~t] [~n.~f] ~m')
flog.layout(layout)

# Create a custom logger to trace variables
flog.layout(layout.tracearg, name='tracer')
x <- 5
flog.info(x, name='tracer')

Example output

NULL
NULL
NULL
INFO [2017-07-24 16:10:09] x: 5

futile.logger documentation built on May 2, 2019, 8:53 a.m.