Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Example code for issue_052 #53

Merged
merged 2 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion R/build_log_entry.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#' @param timestamp logging timestamp as \code{\link{POSIXct}} (normally by calling \code{\link{Sys.time}})
#' @param severity severity level of the log entry ((ERROR, WARN, INFO etc.)
#' @param msg.text Logging message (e. g. error message)
#' @param pid a process id or other text identifier that will be added to msg.text
#' @param call.stack a call stack created by \code{\link{sys.calls}}
#' @param dump.file.name name of the created dump file (leave empty if the \code{\link{tryCatchLog}}
#' argument \code{write.error.dump.file} is \code{FALSE}
Expand All @@ -47,7 +48,7 @@
#' \code{\link{build.log.output}}
#'
#' @note THIS IS A PACKAGE INTERNAL FUNCTION AND THEREFORE NOT EXPORTED.
build.log.entry <- function(timestamp, severity, msg.text, call.stack, dump.file.name, omit.call.stack.items = 0) {
build.log.entry <- function(timestamp, severity, msg.text, pid, call.stack, dump.file.name, omit.call.stack.items = 0) {

stopifnot(inherits(timestamp, "POSIXct"))

Expand All @@ -56,6 +57,7 @@ build.log.entry <- function(timestamp, severity, msg.text, call.stack, dump.file
log.entry <- data.frame(timestamp = timestamp,
severity = severity,
msg.text = msg.text,
pid = ifelse(is.null(pid), NA, pid),
compact.stack.trace = get.pretty.call.stack(call.stack, omit.call.stack.items, compact = TRUE),
full.stack.trace = get.pretty.call.stack(call.stack, omit.call.stack.items),
dump.file.name = dump.file.name,
Expand Down
2 changes: 2 additions & 0 deletions R/build_log_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ build.log.output <- function(log.results,
if (include.severity)
paste0("[", log.results$severity[i], "] "),
log.results$msg.text[i],
if (!is.na(log.results$pid[i]))
paste0(" ", log.results$pid[i]), # No condition required, won't show if NULL
"\n\n",
if (nchar(log.results$dump.file.name[i]) > 0)
paste0("Created dump file: ", log.results$dump.file.name[i], "\n\n"),
Expand Down
4 changes: 3 additions & 1 deletion R/tryCatchLog.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#' \code{error}, \code{warning}, \code{message} and \code{interrupt}.
#' All condition handlers are passed to \code{\link{tryCatch}} as is
#' (no filtering, wrapping or changing of semantics).
#' @param pid a process id or other text identifier that will be added to msg.text
#' @param finally expression to be evaluated at the end
#' @param write.error.dump.file \code{TRUE}: Saves a dump of the workspace and the call stack named
#' \code{dump_<YYYYMMDD>_at_<HHMMSS.sss>_PID_<process id>.rda}.
Expand Down Expand Up @@ -146,6 +147,7 @@
tryCatchLog <- function(expr,
# error = function(e) {if (!is.null(getOption("error", stop))) eval(getOption("error", stop)) }, # getOption("error", default = stop),
...,
pid = NULL,
finally = NULL,
write.error.dump.file = getOption("tryCatchLog.write.error.dump.file", FALSE),
write.error.dump.folder = getOption("tryCatchLog.write.error.dump.folder", "."),
Expand Down Expand Up @@ -197,7 +199,7 @@ tryCatchLog <- function(expr,



log.entry <- build.log.entry(timestamp, severity, log.message, call.stack, dump.file.name, omit.call.stack.items = 1)
log.entry <- build.log.entry(timestamp, severity, log.message, pid, call.stack, dump.file.name, omit.call.stack.items = 1)

if (!is.duplicated.log.entry(log.entry)) {

Expand Down