A quick and easy way to configure the root logger. This is less powerful
then using lgr$config() or lgr$set_*() (see Logger), but reduces the
most common configurations to a single line of code.
Usage
basic_config(
file = NULL,
fmt = "%L [%t] %m",
timestamp_fmt = "%Y-%m-%d %H:%M:%OS3",
threshold = "info",
appenders = NULL,
console = if (is.null(appenders)) "all" else FALSE,
console_fmt = "%L [%t] %m %f",
console_timestamp_fmt = "%H:%M:%OS3",
console_connection = NULL,
memory = FALSE
)Arguments
- file
characterscalar: If notNULLa AppenderFile will be created that logs to this file. If the filename ends in.jsonl, the Appender will be set up to use the JSON Lines format instead of plain text (see AppenderFile and AppenderJson).- fmt
characterscalar: Format to use iffileis supplied and not a.jsonlfile. IfNULLit defaults to"%L [%t] %m"(see format.LogEvent)- timestamp_fmt
see
format.POSIXct()- threshold
characterorintegerscalar. The minimum log level that should be processed by the root logger.- appenders
a single Appender or a list thereof.
- console
logicalscalar or athreshold(see above). Add an appender logs to the console (i.e. displays messages in an interactive R session)- console_fmt
characterscalar: likefmtbut used for console output- console_timestamp_fmt
characterscalar: liketimestamp_fmtbut used for console output- console_connection
see
cat()fileargument.- memory
logicalscalar. or athreshold(see above). Add an Appender that logs to a memory buffer, see alsoshow_log()and AppenderBuffer
Examples
# log to a file
basic_config(file = tempfile())
#> <LoggerRoot> [info] root
#>
#> appenders:
#> file : <AppenderFile> [all] -> /tmp/RtmpXzyffJ/file1c966d61af5c
#> console: <AppenderConsole> [all] -> console
unlink(lgr$appenders$file$file) # cleanup
basic_config(file = tempfile(fileext = "jsonl"))
#> <LoggerRoot> [info] root
#>
#> appenders:
#> file : <AppenderFile> [all] -> /tmp/RtmpXzyffJ/file1c9640d04ec3jsonl
#> console: <AppenderConsole> [all] -> console
unlink(lgr$appenders$file$file) # cleanup
# log debug messages to a memory buffer
basic_config(threshold = "all", memory = "all", console = "info")
#> <LoggerRoot> [all] root
#>
#> appenders:
#> console: <AppenderConsole> [info] -> console
#> memory : <AppenderBuffer> [ all] -> 0 child Appenders
lgr$info("an info message")
#> INFO [06:40:34.623] an info message
lgr$debug("a hidden message")
show_log()
#> INFO [06:40:34] an info message
#> DEBUG [06:40:34] a hidden message
# reset to default config
basic_config()
#> <LoggerRoot> [info] root
#>
#> appenders:
#> console: <AppenderConsole> [all] -> console