sayInfo: Log to multiple loggers (with different thresholds)

View source: R/FutileLoggerUtils.R

sayInfoR Documentation

Log to multiple loggers (with different thresholds)

Description

These are essentially the same as the level-specific loggers in futile.logger, except they each can take a vector of logger names. The futile.logger package makes it easy to log, and allows logging to both a file and the console, but not with different thresholds. The sayLevel loggers described here support this as the default case, but also support any combination of one or more loggers, possibly differing at each point where a message is logged.

Usage

sayTrace(
  msg,
  ...,
  name = paste0(packageName(env = parent.frame()), c(".file", ".console")),
  capture = FALSE
)

sayDebug(
  msg,
  ...,
  name = paste0(packageName(env = parent.frame()), c(".file", ".console")),
  capture = FALSE
)

sayInfo(
  msg,
  ...,
  name = paste0(packageName(env = parent.frame()), c(".file", ".console")),
  capture = FALSE
)

sayWarn(
  msg,
  ...,
  name = paste0(packageName(env = parent.frame()), c(".file", ".console")),
  capture = FALSE
)

sayError(
  msg,
  ...,
  name = paste0(packageName(env = parent.frame()), c(".file", ".console")),
  capture = FALSE
)

sayFatal(
  msg,
  ...,
  name = paste0(packageName(env = parent.frame()), c(".file", ".console")),
  capture = FALSE
)

OFF

Arguments

msg

The message to print, possibly a string with sprintf symbols (like %s), unless capture= TRUE

...

Extra arguments for use by msg, if it is a sprintf message (capture= FALSE), or objects to have the logger format and print starting on the line following a non-sprintf message. (capture= TRUE.)

name

The logger names to use (a vector of strings). By default will use c( package.file, package.code ). A message of the appropriate level with be logged to each.

capture

By default (FALSE), extra object arguments are handled as format variables for the message, which should contain a matching number of sprintf variable symbols. If TRUE, then extra object arguments are handled by the appender layout, by default printed on the next line following msg.

Format

An object of class integer of length 1.

Details

Whether or not a message is propagated depends on each logger's level separately. If only one name is specified, this is essentially identical to a flog.level call. If no names are provided, by default will log to two loggers: "package.file" and "package.console".

All loggers should be defined before being used in a log message. Since loggers are a hierarchical namespace based on the "." separator in the names, each undefined logger passed in causes a logging call to search up the tree of loggers looking for a "fall-back" logger. As a last resort, this will be logged by the root logger. This prevents messages being lost, but can result in the same message being logged multiple times.

To prevent a logger from logging anything, set its threshold to OFF. OFF is exported as another constant for use with loggers and is a higher priority than FATAL No logging function can generate a message with priority greater than FATAL Note, this is not completely consistent with the use of the other constants, where the string can be used. "INFO" and INFO are treated similarly in most cases, whereas "OFF" and OFF are not. Always use the constant OFF (i.e. the value 0) and not the string.

To ensure a logger logs everything, set its logging threshold to "TRACE". No logging function can generate a message with priority lower than TRACE

Value

Returns the message from the last logger named, may be NULL if that logger does not log the message due to threshold issues and flog.carp(TRUE) is not set.

Functions

  • sayTrace(): Print a message to specified loggers with a threshold of TRACE.

  • sayDebug(): Print a message to specified loggers with a threshold of DEBUG or TRACE.

  • sayInfo(): Print a message to specified loggers with a threshold of INFO, DEBUG or TRACE.

  • sayWarn(): Print a message to specified loggers with a threshold of WARN, INFO, DEBUG or TRACE.

  • sayError(): Print a message to specified loggers with a threshold of ERROR, WARN, INFO, DEBUG or TRACE.

  • sayFatal(): Print a message to specified loggers with a threshold of FATAL ERROR, WARN, INFO, DEBUG or TRACE.


jefferys/JefferysRUtils documentation built on Jan. 12, 2024, 9:18 p.m.