daroczig / logger

A lightweight, modern and flexible, log4j and futile.logger inspired logging utility for R
https://daroczig.github.io/logger
280 stars 41 forks source link

Feature request: log traceback in addition to error when stop is called #86

Open DavideMessinaARS opened 3 years ago

DavideMessinaARS commented 3 years ago

I have an algorithm which is divided in various steps, all of them called inside a to_run file.

I want to log not only the errors but the traceback too.

I have written a function that does that:

log_traceback <- function(file_log) {
  file_log <- readLines(file_logfile_log)
  if (substr(tail(file_log, 1), start = 1, stop = 5) == "ERROR"){
    invisible(lapply(.traceback(), log_error))
  }
}

However the function works only when I call it and not when the errors occur.

This means that after each step I would need to call the function which is not ideal for various reasons. (Otherwise the traceback will be overwritten by the next error)

Would it be possible to add an option for logging the traceback inside the log_errors() function? (Or create a log_traceback function)

1beb commented 2 years ago

tryCatchLog does this. https://github.com/aryoda/tryCatchLog

daroczig commented 6 months ago

Thanks for the feature request! As I am busy with other things, I don't think I have the time to work in this in the coming months, so I would highly appreciate if someone can come up with a PR -- so thus I'm now setting the related "Help wanted" label.