Description Arguments Usage Additional Usage Details Author(s) See Also Examples
Provides functions for writing log messages and managing loggers. Typically only the flog.[trace|debug|info|warn|error|fatal] functions need to be used in conjunction with flog.threshold to interactively change the log level.
msg |
The message to log |
name |
The logger name to use |
capture |
Capture print output of variables instead of interpolate |
... |
Optional arguments to populate the format string |
expr |
An expression to evaluate |
finally |
An optional expression to evaluate at the end |
# Conditionally print a log statement at TRACE log level
flog.trace(msg, ..., name=flog.namespace(), capture=FALSE)
# Conditionally print a log statement at DEBUG log level
flog.debug(msg, ..., name=flog.namespace(), capture=FALSE)
# Conditionally print a log statement at INFO log level
flog.info(msg, ..., name=flog.namespace(), capture=FALSE)
# Conditionally print a log statement at WARN log level
flog.warn(msg, ..., name=flog.namespace(), capture=FALSE)
# Conditionally print a log statement at ERROR log level
flog.error(msg, ..., name=flog.namespace(), capture=FALSE)
# Print a log statement at FATAL log level
flog.fatal(msg, ..., name=flog.namespace(), capture=FALSE)
# Execute an expression and capture any warnings or errors ftry(expr, error=stop, finally=NULL)
These functions generally do not need to be called by an end user.
# Get the ROOT logger
flog.logger()
# Get the logger with the specified name
flog.logger(name)
# Set options for the given logger
flog.logger(name, threshold=NULL, appender=NULL, layout=NULL, carp=NULL)
These functions represent the high level interface to futile.logger.
The primary use case for futile.logger is to write out log messages. There are log writers associated with all the predefined log levels: TRACE, DEBUG, INFO, WARN, ERROR, FATAL. Log messages will only be written if the log level is equal to or more urgent than the current threshold. By default the ROOT logger is set to INFO.
> flog.debug("This won't print")
> flog.info("But this %s", 'will')
> flog.warn("As will %s", 'this')
Typically, the built in log level constants are used in the call, which conform to the log4j levels (from least severe to most severe): TRACE, DEBUG, INFO, WARN, ERROR, FATAL. It is not a strict requirement to use these constants (any numeric value will work), though most users should find this level of granularity sufficient.
Loggers are hierarchical in the sense that any requested logger that is undefined will fall back to its most immediate defined parent logger. The absolute parent is ROOT, which is guaranteed to be defined for the system and cannot be deleted. This means that you can specify a new logger directly.
> flog.info("This will fall back to 'my', then 'ROOT'", name='my.logger')
You can also change the threshold or any other setting associated with a logger. This will create an explicit logger where any unspecified options are copied from the parent logger.
> flog.appender(appender.file("foo.log"), name='my')
> flog.threshold(ERROR, name='my.logger')
> flog.info("This won't print", name='my.logger')
> flog.error("This
If you define a logger that you later want to remove, use flog.remove.
The option 'capture' allows you to print out more complicated data structures without a lot of ceremony. This variant doesn't accept format strings and instead appends the value to the next line of output. Consider
> m <- matrix(rnorm(12), nrow=3)
> flog.info("Matrix:",m, capture=TRUE)
which preserves the formatting, whereas using capture=FALSE will have a cluttered output due to recycling.
Brian Lee Yung Rowe
flog.threshold
flog.remove
flog.carp
flog.appender
flog.layout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | flog.threshold(DEBUG)
flog.debug("This debug message will print")
flog.threshold(WARN)
flog.debug("This one won't")
m <- matrix(rnorm(12), nrow=3)
flog.info("Matrix:",m, capture=TRUE)
ftry(log(-1))
## Not run:
s <- c('FCX','AAPL','JPM','AMZN')
p <- TawnyPortfolio(s)
flog.threshold(TRACE,'tawny')
ws <- optimizePortfolio(p, RandomMatrixDenoiser())
z <- getIndexComposition()
flog.threshold(WARN,'tawny')
ws <- optimizePortfolio(p, RandomMatrixDenoiser())
z <- getIndexComposition()
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.