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.2.9000 |
Built: | 2024-12-17 17:23:26 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()
level the level of the message (ALL, DEBUG, INFO, WARN, ERROR, 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 and ERROR messages on and off.
logger.setLevel(level)
logger.setLevel(level)
level |
the level of the message (ALL, DEBUG, INFO, WARN, ERROR, OFF) |
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') ## End(Not run)
## Not run: logger.setLevel('DEBUG') ## 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) |
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 when placed in inst/tests/test.<fn>.R
,
but is not passed from tests/run.all.R
.
logger.setQuitOnSevere(severeQuits)
logger.setQuitOnSevere(severeQuits)
severeQuits |
should R quit on a severe error. |
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 use stderr instead of stdout for logging |
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. |
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. This is set by default to TRUE if interactive or running
inside Rstudio.
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)) })