initSayLoggers: Initialize default loggers

View source: R/FutileLoggerUtils.R

initSayLoggersR Documentation

Initialize default loggers

Description

Sets up the default "package.console" and "package.file" loggers. Use the saylevel function to log simultaneously to them. If you log from a script or a console and don't specify the log file, it will write to the probably hidden file ‘".log"’. Allowed log levels are, in order of decreasing importance: OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE. Messages logged to the console will be just the messages by default, messages logged to a file will be prepended with the log level and the date. This can be changed by modifying the layout parameters.

Usage

initSayLoggers(
  file = packageName(env = parent.frame()) %p% ".log",
  fileLevel = WARN,
  consoleLevel = INFO,
  fileLayout = layout.format("~l [~t] ~m"),
  consoleLayout = layout.format("~m")
)

Arguments

file

The name of the log file, by default ‘"package.log"’ where package is guessed using link{packageName(env=parent.frame())}.

fileLevel

Only messages at least this important will be saved to the log file, by default WARN.

consoleLevel

Only messages at least this important will be printed to the console, by default INFO.

fileLayout

The layout string to use with messages logged to the log file. By default this See flog.layout

consoleLayout

The layout string to use with messages logged to the console. See flog.layout

Value

Nothing, called only for its side effect of initializing loggers.

See Also

futile.logger::flog.layout, futile.logger::flog.logger

Examples

## Not run: 
  # Default settings
  initSayLoggers()

  # Won't be logged
  sayDebug('Initialized logging.')

  # Logged only to console, not file
  sayInfo('Welcome!')
  #> Welcome!

  # Logged to console and file.
  sayWarn("This conversation is being monitored.")
  #> This conversation is being monitored.
  #> [In log file]
  #> WARN [YYYY-MM-DD hh::mm::ss TZ] This conversation is being monitored.

## End(Not run)

jefferys/JefferysRUtils documentation built on June 18, 2024, 4:39 a.m.