AppenderConsole: Log to the console

AppenderConsoleR Documentation

Log to the console

Description

An Appender that outputs to the R console. If you have the package crayon installed log levels will be coloured by default (but you can modify this behaviour by passing a custom Layout).

Super classes

lgr::Filterable -> lgr::Appender -> AppenderConsole

Methods

Public methods

Inherited methods

Method new()

Usage
AppenderConsole$new(
  threshold = NA_integer_,
  layout = LayoutFormat$new(fmt = "%L [%t] %m %f", timestamp_fmt = "%H:%M:%OS3",
    colors = getOption("lgr.colors", list())),
  filters = NULL,
  connection = NULL
)
Arguments
connection

A connection or a character scalar. See the file argument of cat() for more details. Defaults to stdout(), except inside knitr rendering processes where it defaults to stderr().


Method append()

Usage
AppenderConsole$append(event)

Method set_connection()

Usage
AppenderConsole$set_connection(connection)
Arguments
connection

A connection or a character scalar. See the file argument of cat() for more details. Defaults to stdout(), except inside knitr rendering processes where it defaults to stderr().

See Also

LayoutFormat

Other Appenders: AppenderBuffer, AppenderFileRotatingDate, AppenderFileRotatingTime, AppenderFileRotating, AppenderFile, AppenderTable, Appender

Examples

# create a new logger with propagate = FALSE to prevent routing to the root
# logger. Please look at the section "Logger Hirarchies" in the package
# vignette for more info.
lg  <- get_logger("test")$set_propagate(FALSE)

lg$add_appender(AppenderConsole$new())
lg$add_appender(AppenderConsole$new(
  layout = LayoutFormat$new("[%t] %c(): [%n] %m", colors = getOption("lgr.colors"))))

# Will output the message twice because we attached two console appenders
lg$warn("A test message")
lg$config(NULL) # reset config

s-fleck/memlog documentation built on March 6, 2023, 6:52 p.m.