Skip to content

Commit

Permalink
Merge pull request daroczig#139 from pawelru/master
Browse files Browse the repository at this point in the history
support `OFF` log level
  • Loading branch information
daroczig authored Feb 12, 2024
2 parents 9947980 + 2623362 commit ec619ce
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(DEBUG)
export(ERROR)
export(FATAL)
export(INFO)
export(OFF)
export(SUCCESS)
export(TRACE)
export(WARN)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
11 changes: 8 additions & 3 deletions R/levels.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
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
#'
#' 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.
#'
#' 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
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions man/log_levels.Rd

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

11 changes: 11 additions & 0 deletions tests/testthat/test-logger.R
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit ec619ce

Please sign in to comment.