-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add helper functions to automatically log messages/warnings/errors
- Loading branch information
Showing
6 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#' Injects a logger call to standard messages | ||
#' | ||
#' This function uses \code{trace} to add a \code{log_info} function call when \code{message} is called to log the informative messages with the \code{logger} layout and appender. | ||
#' @return | ||
#' @export | ||
#' @examples \dontrun{ | ||
#' log_messages() | ||
#' message('hi there') | ||
#' } | ||
log_messages <- function() { | ||
invisible(suppressMessages(trace( | ||
what = 'message', | ||
trace = substitute(logger::log_info(logger::skip_formatter(paste(list(...), collapse = '')))), | ||
print = FALSE, | ||
where = baseenv()))) | ||
} | ||
|
||
|
||
#' 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. | ||
#' @return | ||
#' @export | ||
#' @examples \dontrun{ | ||
#' log_warnings() | ||
#' for (i in 1:5) { Sys.sleep(runif(1)); warning(i) } | ||
#' } | ||
log_warnings <- function() { | ||
invisible(suppressMessages(trace( | ||
what = 'warning', | ||
trace = substitute(logger::log_warn(logger::skip_formatter(paste(list(...), collapse = '')))), | ||
print = FALSE, | ||
where = baseenv()))) | ||
} | ||
|
||
|
||
#' 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. | ||
#' @return | ||
#' @export | ||
#' @examples \dontrun{ | ||
#' log_errors() | ||
#' stop('foobar') | ||
#' } | ||
log_errors <- function() { | ||
invisible(suppressMessages(trace( | ||
what = 'stop', | ||
trace = substitute(logger::log_error(logger::skip_formatter(paste(list(...), collapse = '')))), | ||
print = FALSE, | ||
where = baseenv()))) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.