From ce1b751b7eb7b4f94dfa9b72bd9607e8ec2795d1 Mon Sep 17 00:00:00 2001 From: Dan Chaltiel Date: Sun, 16 Jan 2022 21:21:17 +0100 Subject: [PATCH 1/3] Remove duplicated condition after it being logged --- R/hooks.R | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/R/hooks.R b/R/hooks.R index c57f2d52..7b798bcf 100644 --- a/R/hooks.R +++ b/R/hooks.R @@ -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 are 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 { @@ -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 errors are 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 { From 2e2d582042b72dca95ec2f50fb31d0d518e13f4e Mon Sep 17 00:00:00 2001 From: "Gergely Daroczi (@daroczig)" Date: Sun, 22 Oct 2023 14:52:52 +0200 Subject: [PATCH 2/3] code style --- R/hooks.R | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/R/hooks.R b/R/hooks.R index 7b798bcf..7a5a8b4b 100644 --- a/R/hooks.R +++ b/R/hooks.R @@ -37,20 +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 are not shown after being logged -#' +#' @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(muffle=getOption("logger_muffle_warnings", FALSE)) { +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") + if (isTRUE(muffle)) { + invokeRestart('muffleWarning') + } } ) } else { @@ -67,20 +67,20 @@ log_warnings <- function(muffle=getOption("logger_muffle_warnings", FALSE)) { #' 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 errors are not thrown after being logged -#' +#' @param muffle if TRUE, the error is not thrown after being logged #' @export #' @examples \dontrun{ #' log_errors() #' stop('foobar') #' } -log_errors <- function(muffle=getOption("logger_muffle_errors", FALSE)) { +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") + if (isTRUE(muffle)) { + invokeRestart('abort') + } } ) } else { From f36d54d2fa7192ee31a0eeb90f8619f849bd6530 Mon Sep 17 00:00:00 2001 From: "Gergely Daroczi (@daroczig)" Date: Sun, 22 Oct 2023 14:53:20 +0200 Subject: [PATCH 3/3] roxygenize muffle options --- man/log_errors.Rd | 5 ++++- man/log_warnings.Rd | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/man/log_errors.Rd b/man/log_errors.Rd index 33f3d576..9680ef3e 100644 --- a/man/log_errors.Rd +++ b/man/log_errors.Rd @@ -4,7 +4,10 @@ \alias{log_errors} \title{Injects a logger call to standard errors} \usage{ -log_errors() +log_errors(muffle = getOption("logger_muffle_errors", FALSE)) +} +\arguments{ +\item{muffle}{if TRUE, the error is not thrown after being logged} } \description{ 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. diff --git a/man/log_warnings.Rd b/man/log_warnings.Rd index ce35d0cf..7a0e9895 100644 --- a/man/log_warnings.Rd +++ b/man/log_warnings.Rd @@ -4,7 +4,10 @@ \alias{log_warnings} \title{Injects a logger call to standard warnings} \usage{ -log_warnings() +log_warnings(muffle = getOption("logger_muffle_warnings", FALSE)) +} +\arguments{ +\item{muffle}{if TRUE, the warning is not shown after being logged} } \description{ 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.