| Title: | Logger Functions for 'PEcAn' |
|---|---|
| Description: | Convenience functions for logging outputs from 'PEcAn', the Predictive Ecosystem Analyzer (LeBauer et al. 2017) <doi:10.1890/12-0137.1>. Enables the user to set what level of messages are printed, as well as whether these messages are written to the console, a file, or both. It also allows control over whether severe errors should stop execution of the 'PEcAn' workflow; this allows strictness when debugging and lenience when running large batches of simulations that should not be terminated by errors in individual models. It is loosely based on the 'log4j' package. |
| Authors: | Rob Kooper [aut, cre], Alexey Shiklomanov [aut], Shashank Singh [aut], Chris Black [aut], University of Illinois, NCSA [cph] |
| Maintainer: | Rob Kooper <[email protected]> |
| License: | BSD_3_clause + file LICENSE |
| Version: | 1.8.4.9000 |
| Built: | 2026-06-05 14:40:52 UTC |
| Source: | https://github.com/PecanProject/pecan |
This function will print a debug message.
logger.debug(msg, ...)logger.debug(msg, ...)
msg |
the message that should be printed. |
... |
any additional text that should be printed. |
Rob Kooper
## Not run: logger.debug('variable', 5) ## End(Not run)## Not run: logger.debug('variable', 5) ## End(Not run)
This function will print an error message.
logger.error(msg, ...)logger.error(msg, ...)
msg |
the message that should be printed. |
... |
any additional text that should be printed. |
Rob Kooper
## Not run: logger.error('system did not converge') ## End(Not run)## Not run: logger.error('system did not converge') ## End(Not run)
This will return the current level configured of the logging messages.
logger.getLevel()logger.getLevel()
Note that logger.setLevel() invisibly returns current level, so
logger.getLevel() is not required to restore the level after a
temporary change.
A string giving the lowest message level that will be reported, one of "ALL", "DEBUG", "INFO", "WARN", "ERROR", "SEVERE", or "OFF".
Rob Kooper
## Not run: logger.getLevel() ## End(Not run)## Not run: logger.getLevel() ## End(Not run)
This function will print an informational message.
logger.info(msg, ...)logger.info(msg, ...)
msg |
the message that should be printed. |
... |
any additional text that should be printed. |
Rob Kooper
## Not run: logger.info('PEcAn version 1.2') ## End(Not run)## Not run: logger.info('PEcAn version 1.2') ## End(Not run)
This function will print a message. This is the function that is responsible for the actual printing of the message.
logger.message(level, msg, ..., wrap = TRUE)logger.message(level, msg, ..., wrap = TRUE)
level |
the level of the message (DEBUG, INFO, WARN, ERROR) |
msg |
the message that should be printed. |
... |
any additional text that should be printed. |
wrap |
Whether or not to wrap long messages (default =
|
This is a place holder and will be later filled in with a more complex logging set
Rob Kooper
## Not run: logger.message('DEBUG', 'variable', 5) ## End(Not run)## Not run: logger.message('DEBUG', 'variable', 5) ## End(Not run)
This will configure the logger level. This allows to turn DEBUG, INFO, WARN, ERROR, and SEVERE messages on and off.
logger.setLevel(level)logger.setLevel(level)
level |
the level of the message. One of "ALL", "DEBUG", "INFO", "WARN", "ERROR", "SEVERE", or "OFF". |
Note that this controls printing of messages and does not change other behavior.
In particular, suppressing SEVERE by setting the level to "OFF" does not prevent
logger.severe() from signaling an error (and terminating the program if
logger.setQuitOnSevere(TRUE)).
When logger level is set, the previous level is returned invisibly.
This can be passed to logger.setLevel() to restore the previous level.
Rob Kooper
## Not run: logger.setLevel('DEBUG') # Temporarily turn logger off old_logger_level <- logger.setLevel("OFF") # code here logger.setLevel(old_logger_level) ## End(Not run)## Not run: logger.setLevel('DEBUG') # Temporarily turn logger off old_logger_level <- logger.setLevel("OFF") # code here logger.setLevel(old_logger_level) ## End(Not run)
The name of the file where the logging information should be written to.
logger.setOutputFile(filename)logger.setOutputFile(filename)
filename |
the file to send the log messages to (or NA to not write to file) |
Invisibly, the previously set filename. This can be used to restore settings after a temporary change.
Rob Kooper
## Not run: logger.setOutputFile('pecan.log') ## End(Not run)## Not run: logger.setOutputFile('pecan.log') ## End(Not run)
The default is for a non-interactive session to quit. Setting this to false is especially useful for running tests.
logger.setQuitOnSevere(severeQuits)logger.setQuitOnSevere(severeQuits)
severeQuits |
should R quit on a severe error. |
invisibly, the previous value of severeQuits.
This can be used to restore settings after a temporary change.
Rob Kooper
## Not run: logger.setQuitOnSevere(FALSE) ## End(Not run)## Not run: logger.setQuitOnSevere(FALSE) ## End(Not run)
Should the logging to be printed to the console or not.
logger.setUseConsole(console, stderr = TRUE)logger.setUseConsole(console, stderr = TRUE)
console |
set to true to print logging to console. |
stderr |
set to true (default) to log to stderr instead of stdout |
Invisibly, a list of the previously set values of console
and stderr. This can be used to restore the previous settings after a
temporary change.
Rob Kooper
## Not run: logger.setUseConsole(TRUE) ## End(Not run)## Not run: logger.setUseConsole(TRUE) ## End(Not run)
The default is for 60 chars per line. Setting this to any value will wrap the line when printing a message at that many chars.
logger.setWidth(width)logger.setWidth(width)
width |
number of chars to print before wrapping to next line. |
Invisibly, the previously set width. This can be used to restore settings after a temporary change.
David LeBauer
## Not run: logger.setWidth(70) ## End(Not run)## Not run: logger.setWidth(70) ## End(Not run)
This function will print a message and stop execution of the code. This should only be used if the application should terminate.
logger.severe(msg, ..., wrap = TRUE)logger.severe(msg, ..., wrap = TRUE)
msg |
the message that should be printed. |
... |
any additional text that should be printed. |
wrap |
Whether or not to wrap long messages (default =
|
Set logger.setQuitOnSevere(FALSE) to avoid terminating
the session. The default is to not quit if running interactively.
Rob Kooper
## Not run: logger.severe('missing parameters') ## End(Not run)## Not run: logger.severe('missing parameters') ## End(Not run)
This function will print a warning message.
logger.warn(msg, ...)logger.warn(msg, ...)
msg |
the message that should be printed. |
... |
any additional text that should be printed. |
Rob Kooper
## Not run: logger.warn('detected NA values') ## End(Not run)## Not run: logger.warn('detected NA values') ## End(Not run)
logger.info() or base::message().Note that for this to work properly in the PEcAn.logger
functions, you should always add the wrap = FALSE argument, and
probably add a newline ("\n") before the output of this function.
print2string(x, ...)print2string(x, ...)
x |
Object to print |
... |
Additional arguments to |
Output of print(x, ...), captured as string
Alexey Shiklomanov
logger.info("First few rows of Iris:\n", print2string(iris[1:10, -5]), wrap = FALSE) df <- data.frame(test = c("download", "process", "plot"), status = c(TRUE, TRUE, FALSE)) logger.debug("Current status:\n", print2string(df, row.names = FALSE), wrap = FALSE)logger.info("First few rows of Iris:\n", print2string(iris[1:10, -5]), wrap = FALSE) df <- data.frame(test = c("download", "process", "plot"), status = c(TRUE, TRUE, FALSE)) logger.debug("Current status:\n", print2string(df, row.names = FALSE), wrap = FALSE)
Similar to base::stopifnot, but allows you to use a custom message and
logger level. If all conditions are TRUE, silently exit.
severeifnot(msg, ...) errorifnot(msg, ...) warnifnot(msg, ...) infoifnot(msg, ...) debugifnot(msg, ...)severeifnot(msg, ...) errorifnot(msg, ...) warnifnot(msg, ...) infoifnot(msg, ...) debugifnot(msg, ...)
msg |
Logger message to write, as a single character string. |
... |
Conditions to evaluate |
Conditions can be vectorized, or can return non-logical values.The
underlying function automatically applies isTRUE(all(.)) to the
conditions.
Invisibly, TRUE if conditions are met, FALSE otherwise
a <- 1:5 b <- list(6, 7, 8) debugifnot("By the way, something is not a list.", is.list(a), is.list(b)) infoifnot("Something is not a list.", is.list(a), is.list(b)) warnifnot("I would prefer it if you used lists.", is.list(a), is.list(b)) errorifnot("You should definitely use lists.", is.list(a), is.list(b)) try({ severeifnot("I cannot deal with the fact that something is not a list.", is.list(a), is.list(b)) })a <- 1:5 b <- list(6, 7, 8) debugifnot("By the way, something is not a list.", is.list(a), is.list(b)) infoifnot("Something is not a list.", is.list(a), is.list(b)) warnifnot("I would prefer it if you used lists.", is.list(a), is.list(b)) errorifnot("You should definitely use lists.", is.list(a), is.list(b)) try({ severeifnot("I cannot deal with the fact that something is not a list.", is.list(a), is.list(b)) })