% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/layout.R
\name{flog.layout}
\alias{flog.layout}
\alias{layout.simple}
\alias{layout.simple.parallel}
\alias{layout.format}
\alias{layout.tracearg}
\alias{layout.json}
\alias{layout.graylog}
\alias{layout.glue}
\alias{layout.colored}
\title{Manage layouts within the 'futile.logger' sub-system}
\arguments{
\item{\dots}{Used internally by lambda.r}
}
\description{
Provides functions for managing layouts. Typically 'flog.layout' is only
used when manually creating a logging configuration.
}
\section{Usage}{

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

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

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

# Decorate log messages with a standard format colored by log level\cr
layout.colored(level, msg, ...)

# Decorate log messages with a standard format using glue instead of sprintf\cr
layout.glue(level, msg, ...)

# Decorate log messages with a standard format and a pid\cr
layout.simple.parallel(level, msg, ...)

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

# Decorate log messages using a custom format\cr
layout.format(format, datetime.fmt="%Y-%m-%d %H:%M:%S")

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

# Generate log messages in a Graylog2 HTTP GELF accetable format
layout.graylog(common.fields)
}

\section{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 
\code{flog.layout}. The \code{flog.layout} function is used internally
to get the registered layout function. It is kept visible so 
user-level introspection is possible.

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

This is the default layout for the ROOT logger.

\code{layout.format} allows you to specify the format string to use 
in printing a message. The following tokens are available.
\describe{
\item{~l}{Log level}
\item{~t}{Timestamp}
\item{~n}{Namespace}
\item{~f}{The calling function}
\item{~m}{The message}
\item{~p}{The process PID}
\item{~i}{Logger name}
}

\code{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"]\}

\code{layout.tracearg} is a special layout that takes a variable
and prints its name and contents.

\code{layout.graylog} is a special layout for use with the appender.graylog to
generate json acceptable to a Graylog2 HTTP GELF endpoint. Standard fields to
be included with every message can be included by setting the common.fields
to a list of properties. E.g.: 

flog.layout(layout.graylog(common.fields = list(host_ip = "10.10.11.23", 
                                                env = "production")))
}

\examples{
# 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')
}
\seealso{
\code{\link{flog.logger}} \code{\link{flog.appender}}
}
\author{
Brian Lee Yung Rowe
}
\keyword{data}
