diff --git a/NAMESPACE b/NAMESPACE index 10859567..11cc8a33 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,7 @@ export(DEBUG) export(ERROR) export(FATAL) export(INFO) +export(OFF) export(SUCCESS) export(TRACE) export(WARN) diff --git a/NEWS.md b/NEWS.md index 9f7df816..a857ee2f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # logger 0.2.9000 (development) +## New features + +* support `OFF` log level (#138, @pawelru) + # logger 0.2.2 (2021-10-10) Maintenance release: diff --git a/R/levels.R b/R/levels.R index 68cda571..5ad7fedb 100644 --- a/R/levels.R +++ b/R/levels.R @@ -1,4 +1,4 @@ -log_levels_supported <- c('FATAL', 'ERROR', 'WARN', 'SUCCESS', 'INFO', 'DEBUG', 'TRACE') +log_levels_supported <- c('OFF', 'FATAL', 'ERROR', 'WARN', 'SUCCESS', 'INFO', 'DEBUG', 'TRACE') #' Log levels #' @@ -6,7 +6,8 @@ log_levels_supported <- c('FATAL', 'ERROR', 'WARN', 'SUCCESS', 'INFO', 'DEBUG', #' #' List of supported log levels: #' \enumerate{ -#' \item \code{FATAL} severe error that will prevent the application from continuing +#' \item \code{OFF} No events will be logged +#' \item \code{FATAL} Severe error that will prevent the application from continuing #' \item \code{ERROR} An error in the application, possibly recoverable #' \item \code{WARN} An event that might possible lead to an error #' \item \code{SUCCESS} An explicit success event above the INFO level that you want to log @@ -15,7 +16,7 @@ log_levels_supported <- c('FATAL', 'ERROR', 'WARN', 'SUCCESS', 'INFO', 'DEBUG', #' \item \code{TRACE} A fine-grained debug message, typically capturing the flow through the application. #' } #' @references \url{https://logging.apache.org/log4j/2.0/javadoc/log4j-api/org/apache/logging/log4j/Level.html}, \url{https://logging.apache.org/log4j/2.x/manual/customloglevels.html} -#' @aliases log_levels FATAL ERROR WARN SUCCESS INFO DEBUG TRACE +#' @aliases log_levels OFF FATAL ERROR WARN SUCCESS INFO DEBUG TRACE #' @rdname log_levels #' @usage #' TRACE @@ -31,6 +32,10 @@ log_levels_supported <- c('FATAL', 'ERROR', 'WARN', 'SUCCESS', 'INFO', 'DEBUG', #' ERROR #' #' FATAL +#' +#' OFF +#' @export +OFF <- structure(0L, level = 'OFF', class = c('loglevel', 'integer')) #' @export FATAL <- structure(100L, level = 'FATAL', class = c('loglevel', 'integer')) #' @export diff --git a/man/log_levels.Rd b/man/log_levels.Rd index 7587707a..2efe13b4 100644 --- a/man/log_levels.Rd +++ b/man/log_levels.Rd @@ -1,9 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/levels.R \docType{data} -\name{FATAL} -\alias{FATAL} +\name{OFF} +\alias{OFF} \alias{log_levels} +\alias{FATAL} \alias{ERROR} \alias{WARN} \alias{SUCCESS} @@ -28,6 +29,8 @@ WARN ERROR FATAL + +OFF } \description{ The standard Apache logj4 log levels plus a custom level for \code{SUCCESS}. For the full list of these log levels and suggested usage, check the below Details. @@ -35,7 +38,8 @@ The standard Apache logj4 log levels plus a custom level for \code{SUCCESS}. For \details{ List of supported log levels: \enumerate{ - \item \code{FATAL} severe error that will prevent the application from continuing + \item \code{OFF} No events will be logged + \item \code{FATAL} Severe error that will prevent the application from continuing \item \code{ERROR} An error in the application, possibly recoverable \item \code{WARN} An event that might possible lead to an error \item \code{SUCCESS} An explicit success event above the INFO level that you want to log diff --git a/tests/testthat/test-logger.R b/tests/testthat/test-logger.R index bcc42ba7..12248cff 100644 --- a/tests/testthat/test-logger.R +++ b/tests/testthat/test-logger.R @@ -27,6 +27,17 @@ test_that('log levels', { expect_output(log_level(as.loglevel(600L), 'foo'), NA) }) +log_threshold(OFF) +test_that('log levels - OFF', { + expect_output(log_fatal('foo'), NA) + expect_output(log_error('foo'), NA) + expect_output(log_warn('foo'), NA) + expect_output(log_success('foo'), NA) + expect_output(log_info('foo'), NA) + expect_output(log_debug('foo'), NA) + expect_output(log_trace('foo'), NA) +}) + log_threshold(TRACE) test_that('log thresholds', { expect_output(log_fatal('foo'), 'FATAL.*foo')