| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/Layout.R |
| 3 |
\name{LayoutGlue} |
| 4 |
\alias{LayoutGlue} |
| 5 |
\title{Format Log Events as Text via glue} |
| 6 |
\description{ |
| 7 |
Format a \link{LogEvent} as human readable text using \link[glue:glue]{glue::glue}. The function |
| 8 |
is evaluated in an environment in which it has access to all elements of |
| 9 |
the \link{LogEvent} (see examples). This is more flexible than \link{LayoutFormat}, |
| 10 |
but also more complex and slightly less performant. |
| 11 |
} |
| 12 |
\examples{ |
| 13 |
lg <- get_logger("test")$ |
| 14 |
set_appenders(AppenderConsole$new())$ |
| 15 |
set_propagate(FALSE) |
| 16 |
|
| 17 |
lg$appenders[[1]]$set_layout(LayoutGlue$new()) |
| 18 |
lg$fatal("test") |
| 19 |
|
| 20 |
|
| 21 |
# All fields of the LogEvent are available, even custom ones |
| 22 |
lg$appenders[[1]]$layout$set_fmt( |
| 23 |
"{logger} {level_name}({level}) {caller}: {toupper(msg)} {{custom: {custom}}}" |
| 24 |
) |
| 25 |
lg$fatal("test", custom = "foobar") |
| 26 |
lg$config(NULL) # reset logger config |
| 27 |
} |
| 28 |
\seealso{ |
| 29 |
lgr exports a number of formatting utility functions that are |
| 30 |
useful for layout glue: \code{\link[=colorize_levels]{colorize_levels()}}, \code{\link[=pad_left]{pad_left()}}, \code{\link[=pad_right]{pad_right()}}. |
| 31 |
|
| 32 |
Other Layouts: |
| 33 |
\code{\link{Layout}}, |
| 34 |
\code{\link{LayoutFormat}}, |
| 35 |
\code{\link{LayoutJson}} |
| 36 |
} |
| 37 |
\concept{Layouts} |
| 38 |
\section{Super class}{ |
| 39 |
\code{\link[lgr:Layout]{lgr::Layout}} -> \code{LayoutGlue} |
| 40 |
} |
| 41 |
\section{Active bindings}{ |
| 42 |
\if{html}{\out{<div class="r6-active-bindings">}} |
| 43 |
\describe{ |
| 44 |
\item{\code{fmt}}{A string that will be interpreted by \code{\link[glue:glue]{glue::glue()}}} |
| 45 |
} |
| 46 |
\if{html}{\out{</div>}} |
| 47 |
} |
| 48 |
\section{Methods}{ |
| 49 |
\subsection{Public methods}{ |
| 50 |
\itemize{ |
| 51 |
\item \href{#method-LayoutGlue-new}{\code{LayoutGlue$new()}} |
| 52 |
\item \href{#method-LayoutGlue-format_event}{\code{LayoutGlue$format_event()}} |
| 53 |
\item \href{#method-LayoutGlue-set_fmt}{\code{LayoutGlue$set_fmt()}} |
| 54 |
\item \href{#method-LayoutGlue-set_colors}{\code{LayoutGlue$set_colors()}} |
| 55 |
\item \href{#method-LayoutGlue-toString}{\code{LayoutGlue$toString()}} |
| 56 |
\item \href{#method-LayoutGlue-clone}{\code{LayoutGlue$clone()}} |
| 57 |
} |
| 58 |
} |
| 59 |
\if{html}{\out{ |
| 60 |
<details open><summary>Inherited methods</summary> |
| 61 |
<ul> |
| 62 |
<li><span class="pkg-link" data-pkg="lgr" data-topic="Layout" data-id="set_excluded_fields"><a href='../../lgr/html/Layout.html#method-Layout-set_excluded_fields'><code>lgr::Layout$set_excluded_fields()</code></a></span></li> |
| 63 |
</ul> |
| 64 |
</details> |
| 65 |
}} |
| 66 |
\if{html}{\out{<hr>}} |
| 67 |
\if{html}{\out{<a id="method-LayoutGlue-new"></a>}} |
| 68 |
\if{latex}{\out{\hypertarget{method-LayoutGlue-new}{}}} |
| 69 |
\subsection{Method \code{new()}}{ |
| 70 |
\subsection{Usage}{ |
| 71 |
\if{html}{\out{<div class="r">}}\preformatted{LayoutGlue$new( |
| 72 |
fmt = "{pad_right(colorize_levels(toupper(level_name)), 5)} [{timestamp}] {msg}" |
| 73 |
)}\if{html}{\out{</div>}} |
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
\if{html}{\out{<hr>}} |
| 78 |
\if{html}{\out{<a id="method-LayoutGlue-format_event"></a>}} |
| 79 |
\if{latex}{\out{\hypertarget{method-LayoutGlue-format_event}{}}} |
| 80 |
\subsection{Method \code{format_event()}}{ |
| 81 |
\subsection{Usage}{ |
| 82 |
\if{html}{\out{<div class="r">}}\preformatted{LayoutGlue$format_event(event)}\if{html}{\out{</div>}} |
| 83 |
} |
| 84 |
|
| 85 |
} |
| 86 |
\if{html}{\out{<hr>}} |
| 87 |
\if{html}{\out{<a id="method-LayoutGlue-set_fmt"></a>}} |
| 88 |
\if{latex}{\out{\hypertarget{method-LayoutGlue-set_fmt}{}}} |
| 89 |
\subsection{Method \code{set_fmt()}}{ |
| 90 |
\subsection{Usage}{ |
| 91 |
\if{html}{\out{<div class="r">}}\preformatted{LayoutGlue$set_fmt(x)}\if{html}{\out{</div>}} |
| 92 |
} |
| 93 |
|
| 94 |
} |
| 95 |
\if{html}{\out{<hr>}} |
| 96 |
\if{html}{\out{<a id="method-LayoutGlue-set_colors"></a>}} |
| 97 |
\if{latex}{\out{\hypertarget{method-LayoutGlue-set_colors}{}}} |
| 98 |
\subsection{Method \code{set_colors()}}{ |
| 99 |
\subsection{Usage}{ |
| 100 |
\if{html}{\out{<div class="r">}}\preformatted{LayoutGlue$set_colors(x)}\if{html}{\out{</div>}} |
| 101 |
} |
| 102 |
|
| 103 |
} |
| 104 |
\if{html}{\out{<hr>}} |
| 105 |
\if{html}{\out{<a id="method-LayoutGlue-toString"></a>}} |
| 106 |
\if{latex}{\out{\hypertarget{method-LayoutGlue-toString}{}}} |
| 107 |
\subsection{Method \code{toString()}}{ |
| 108 |
\subsection{Usage}{ |
| 109 |
\if{html}{\out{<div class="r">}}\preformatted{LayoutGlue$toString()}\if{html}{\out{</div>}} |
| 110 |
} |
| 111 |
|
| 112 |
} |
| 113 |
\if{html}{\out{<hr>}} |
| 114 |
\if{html}{\out{<a id="method-LayoutGlue-clone"></a>}} |
| 115 |
\if{latex}{\out{\hypertarget{method-LayoutGlue-clone}{}}} |
| 116 |
\subsection{Method \code{clone()}}{ |
| 117 |
The objects of this class are cloneable with this method. |
| 118 |
\subsection{Usage}{ |
| 119 |
\if{html}{\out{<div class="r">}}\preformatted{LayoutGlue$clone(deep = FALSE)}\if{html}{\out{</div>}} |
| 120 |
} |
| 121 |
|
| 122 |
\subsection{Arguments}{ |
| 123 |
\if{html}{\out{<div class="arguments">}} |
| 124 |
\describe{ |
| 125 |
\item{\code{deep}}{Whether to make a deep clone.} |
| 126 |
} |
| 127 |
\if{html}{\out{</div>}} |
| 128 |
} |
| 129 |
} |
| 130 |
} |