Skip to content

Commit

Permalink
Merge pull request daroczig#100 from DanChaltiel/patch-1
Browse files Browse the repository at this point in the history
Remove duplicated condition after it being logged
  • Loading branch information
daroczig authored Oct 22, 2023
2 parents 830f7e4 + f36d54d commit d554e28
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
12 changes: 10 additions & 2 deletions R/hooks.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@ log_messages <- function() {
#' Injects a logger call to standard warnings
#'
#' This function uses \code{trace} to add a \code{log_warn} function call when \code{warning} is called to log the warning messages with the \code{logger} layout and appender.
#' @param muffle if TRUE, the warning is not shown after being logged
#' @export
#' @examples \dontrun{
#' log_warnings()
#' for (i in 1:5) { Sys.sleep(runif(1)); warning(i) }
#' }
log_warnings <- function() {
log_warnings <- function(muffle = getOption('logger_muffle_warnings', FALSE)) {
if (R.Version()$major >= 4) {
globalCallingHandlers(
warning = function(m) {
logger::log_warn(m$message)
if (isTRUE(muffle)) {
invokeRestart('muffleWarning')
}
}
)
} else {
Expand All @@ -63,16 +67,20 @@ log_warnings <- function() {
#' Injects a logger call to standard errors
#'
#' This function uses \code{trace} to add a \code{log_error} function call when \code{stop} is called to log the error messages with the \code{logger} layout and appender.
#' @param muffle if TRUE, the error is not thrown after being logged
#' @export
#' @examples \dontrun{
#' log_errors()
#' stop('foobar')
#' }
log_errors <- function() {
log_errors <- function(muffle = getOption('logger_muffle_errors', FALSE)) {
if (R.Version()$major >= 4) {
globalCallingHandlers(
error = function(m) {
logger::log_error(m$message)
if (isTRUE(muffle)) {
invokeRestart('abort')
}
}
)
} else {
Expand Down
5 changes: 4 additions & 1 deletion man/log_errors.Rd

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

5 changes: 4 additions & 1 deletion man/log_warnings.Rd

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

0 comments on commit d554e28

Please sign in to comment.