Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 39 additions & 15 deletions base/logger/R/logger.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ logger.error <- function(msg, ...) {
##' This function will print a message and stop execution of the code. This
##' should only be used if the application should terminate.
##'
##' set \code{\link{logger.setQuitOnSevere}(FALSE)} to avoid terminating
##' the session. This is set by default to TRUE if interactive or running
##' inside Rstudio.
##' Set \code{\link{logger.setQuitOnSevere}(FALSE)} to avoid terminating
##' the session. The default is to not quit if running interactively.
##'
##' @param msg the message that should be printed.
##' @param ... any additional text that should be printed.
Expand Down Expand Up @@ -173,16 +172,28 @@ logger.message <- function(level, msg, ..., wrap = TRUE) {
##' Configure logging level.
##'
##' This will configure the logger level. This allows to turn DEBUG, INFO,
##' WARN and ERROR messages on and off.
##' WARN, ERROR, and SEVERE messages on and 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)`).
##'
##' @param level the level of the message. One of "ALL", "DEBUG", "INFO", "WARN",
##' "ERROR", "SEVERE", or "OFF".
##'
##' @param level the level of the message (ALL, DEBUG, INFO, WARN, ERROR, OFF)
##' @export
##' @return When logger level is set, the previous level is returned invisibly.
##' This can be passed to `logger.setLevel()` to restore the previous level.
##' @author Rob Kooper
##' @examples
##' \dontrun{
##' logger.setLevel('DEBUG')
##'
##' # Temporarily turn logger off
##' old_logger_level <- logger.setLevel("OFF")
##' # code here
##' logger.setLevel(old_logger_level)
##' }
logger.setLevel <- function(level) {
original_level <- logger.getLevel()
Expand All @@ -193,14 +204,22 @@ logger.setLevel <- function(level) {


## Given the string representation this will return the numeric value
## DEBUG = 10
## INFO = 20
## WARN = 30
## ERROR = 40
## ALL = 99
##
##@return level the level of the message
##@author Rob Kooper
## Supported levels
## ALL = 0
## DEBUG = 10
## INFO = 20
## WARN = 30
## ERROR = 40
## SEVERE = 50
## OFF = 60
##
## SEVERE is treated as more serious than ERROR,
## and will terminate the session if `logger.setQuitOnSevere(TRUE)`
## or call stop() otherwise
##
## @return level the level of the message
## @author Rob Kooper
logger.getLevelNumber <- function(level) {
if (toupper(level) == "ALL") {
return(0)
Expand All @@ -213,7 +232,7 @@ logger.getLevelNumber <- function(level) {
} else if (toupper(level) == "ERROR") {
return(40)
} else if (toupper(level) == "SEVERE") {
return(40)
return(50)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

} else if (toupper(level) == "OFF") {
return(60)
} else {
Expand All @@ -225,9 +244,14 @@ logger.getLevelNumber <- function(level) {

##' Get configured logging level.
##'
##' This will return the current level configured of the logging messages
##' This will return the current level configured of the logging messages.
##'
##' Note that `logger.setLevel()` invisibly returns current level, so
##' `logger.getLevel()` is not required to restore the level after a
##' temporary change.
##'
##' @return level the level of the message (ALL, DEBUG, INFO, WARN, ERROR, OFF)
##' @return A string giving the lowest message level that will be reported, one of
##' "ALL", "DEBUG", "INFO", "WARN", "ERROR", "SEVERE", or "OFF".
##' @export
##' @author Rob Kooper
##' @examples
Expand Down
10 changes: 8 additions & 2 deletions base/logger/man/logger.getLevel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions base/logger/man/logger.setLevel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion base/logger/man/logger.severe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading