% Generated by roxygen2: do not edit by hand % Please edit documentation in R/Appender.R \name{AppenderFile} \alias{AppenderFile} \alias{AppenderJson} \title{Log to a file} \description{ A simple Appender that outputs to a file in the file system. If you plan to log to text files, consider logging to JSON files and take a look at \link{AppenderJson}, which is a shortcut for \code{AppenderFile} preconfigured with \code{\link{LayoutJson}}. } \examples{ lg <- get_logger("test") default <- tempfile() fancy <- tempfile() json <- tempfile() lg$add_appender(AppenderFile$new(default), "default") lg$add_appender( AppenderFile$new(fancy, layout = LayoutFormat$new("[\%t] \%c(): \%L \%m")), "fancy" ) lg$add_appender( AppenderFile$new(json, layout = LayoutJson$new()), "json" ) lg$info("A test message") readLines(default) readLines(fancy) readLines(json) # cleanup lg$config(NULL) unlink(default) unlink(fancy) unlink(json) tf <- tempfile() lg <- get_logger("test")$ set_appenders(AppenderJson$new(tf))$ set_propagate(FALSE) lg$info("A test message") lg$info("A test message \%s strings", "with format strings", and = "custom_fields") lg$appenders[[1]]$show() lg$appenders[[1]]$data # cleanup lg$config(NULL) unlink(tf) } \seealso{ \link{LayoutFormat}, \link{LayoutJson} \link{LayoutFormat}, \link{LayoutJson} Other Appenders: \code{\link{Appender}}, \code{\link{AppenderBuffer}}, \code{\link{AppenderConsole}}, \code{\link{AppenderFileRotating}}, \code{\link{AppenderFileRotatingDate}}, \code{\link{AppenderFileRotatingTime}}, \code{\link{AppenderTable}} Other Appenders: \code{\link{Appender}}, \code{\link{AppenderBuffer}}, \code{\link{AppenderConsole}}, \code{\link{AppenderFileRotating}}, \code{\link{AppenderFileRotatingDate}}, \code{\link{AppenderFileRotatingTime}}, \code{\link{AppenderTable}} } \concept{Appenders} \section{Super classes}{ \code{\link[lgr:Filterable]{lgr::Filterable}} -> \code{\link[lgr:Appender]{lgr::Appender}} -> \code{AppenderFile} } \section{Active bindings}{ \if{html}{\out{
}} \describe{ \item{\code{file}}{\code{character} scalar. path to the log file} \item{\code{data}}{\code{data.frame}. Contents of \code{file} parsed to a \code{data.frame} if used with a \link{Layout} that supports parsing of log file data (notably \link{LayoutJson}). Will throw an error if \code{Layout} does not support parsing.} \item{\code{data}}{\code{character} scalar. Like \verb{$data}, but returns a \code{data.table} instead (requires the \strong{data.table} package).} } \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ \itemize{ \item \href{#method-AppenderFile-new}{\code{AppenderFile$new()}} \item \href{#method-AppenderFile-append}{\code{AppenderFile$append()}} \item \href{#method-AppenderFile-set_file}{\code{AppenderFile$set_file()}} \item \href{#method-AppenderFile-show}{\code{AppenderFile$show()}} } } \if{html}{\out{
Inherited methods

- `lgr::Filterable$add_filter()`
- `lgr::Filterable$filter()`
- `lgr::Filterable$remove_filter()`
- `lgr::Filterable$set_filters()`
- `lgr::Appender$format()`
- `lgr::Appender$set_layout()`
- `lgr::Appender$set_threshold()`

}} \if{html}{\out{

}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-AppenderFile-new}{}}} \subsection{Method \code{new()}}{ \subsection{Usage}{ \if{html}{\out{
}}\preformatted{AppenderFile$new( file, threshold = NA_integer_, layout = LayoutFormat$new(), filters = NULL )}\if{html}{\out{
}} } } \if{html}{\out{

}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-AppenderFile-append}{}}} \subsection{Method \code{append()}}{ \subsection{Usage}{ \if{html}{\out{
}}\preformatted{AppenderFile$append(event)}\if{html}{\out{
}} } } \if{html}{\out{

}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-AppenderFile-set_file}{}}} \subsection{Method \code{set_file()}}{ Set a log file \subsection{Usage}{ \if{html}{\out{
}}\preformatted{AppenderFile$set_file(file)}\if{html}{\out{
}} } \subsection{Arguments}{ \if{html}{\out{
}} \describe{ \item{\code{file}}{\code{character} scalar. Path to the log file. If \code{file} does not exist it will be created.} } \if{html}{\out{
}} } } \if{html}{\out{

}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-AppenderFile-show}{}}} \subsection{Method \code{show()}}{ Display the contents of the log file. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{AppenderFile$show(threshold = NA_integer_, n = 20L)}\if{html}{\out{
}} } \subsection{Arguments}{ \if{html}{\out{
}} \describe{ \item{\code{threshold}}{\code{character} or \code{integer} scalar. The minimum log level that should be displayed.} \item{\code{n}}{\code{integer} scalar. Show only the last \code{n} log entries that match \code{threshold}.} } \if{html}{\out{
}} } } } \section{Super classes}{ \code{\link[lgr:Filterable]{lgr::Filterable}} -> \code{\link[lgr:Appender]{lgr::Appender}} -> \code{\link[lgr:AppenderFile]{lgr::AppenderFile}} -> \code{AppenderJson} } \section{Methods}{ \subsection{Public methods}{ \itemize{ \item \href{#method-AppenderJson-new}{\code{AppenderJson$new()}} } } \if{html}{\out{
Inherited methods

- `lgr::Filterable$add_filter()`
- `lgr::Filterable$filter()`
- `lgr::Filterable$remove_filter()`
- `lgr::Filterable$set_filters()`
- `lgr::Appender$format()`
- `lgr::Appender$set_layout()`
- `lgr::Appender$set_threshold()`
- `lgr::AppenderFile$append()`
- `lgr::AppenderFile$set_file()`
- `lgr::AppenderFile$show()`

}} \if{html}{\out{

}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-AppenderJson-new}{}}} \subsection{Method \code{new()}}{ \subsection{Usage}{ \if{html}{\out{
}}\preformatted{AppenderJson$new( file, threshold = NA_integer_, layout = LayoutJson$new(), filters = NULL )}\if{html}{\out{
}} } } }