This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from HendrikSchultheis/debug
Logging
- Loading branch information
Showing
12 changed files
with
140 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
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,37 @@ | ||
|
||
wilson.globals <- new.env(parent = emptyenv()) | ||
|
||
#' set a log4r logger used within the package | ||
#' | ||
#' @param logger A logger object see \code{\link[log4r]{create.logger}}. NULL to disable logging. | ||
#' @param token Set a unique identifier for this logger. | ||
#' | ||
#' @details This function will save each logger in the wilson.globals environment. Each logger is stored by the name 'logger'[token] (e.g. 'logger6b821824b0b53b1a3e8f531a34d0d6e6'). | ||
#' @details Use onSessionEnded to clean up after logging. See \code{\link[shiny]{onFlush}}. | ||
#' | ||
#' @export | ||
set_logger <- function(logger, token = NULL) { | ||
if(is.null(logger) || is(logger, "logger")) { | ||
assign(x = paste0("logger", token), value = logger, envir = wilson.globals) | ||
} | ||
} | ||
|
||
#' logger message convenience function | ||
#' | ||
#' @param message String of message to be written in log. See \code{\link[log4r]{levellog}}. | ||
#' @param level Set priority level of the message (number or character). See \code{\link[log4r]{levellog}}. | ||
#' @param token Use token bound to this identifier. | ||
#' | ||
log_message <- function(message, level = c("DEBUG", "INFO", "WARN", "ERROR", "FATAL"), token = NULL) { | ||
logger <- get(paste0("logger", token), envir = wilson.globals) | ||
|
||
if(!is.null(logger)) { | ||
switch(level, | ||
DEBUG = log4r::debug(logger, message), | ||
INFO = log4r::info(logger, message), | ||
WARN = log4r::warn(logger, message), | ||
ERROR = log4r::error(logger, message), | ||
FATAL = log4r::fatal(logger, message) | ||
) | ||
} | ||
} |
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
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
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.