The function above initializes the log and I am calling this mypackage::init_logger() in another function mypackage::get_data(client, dimensions, metrics, start_date, end_date, ...) where I want to capture certain information as well as any errors that might occur, therefore the log_errors()is crucial in order to debug if anything goes wrong. Everything works fine if this function is called in a regular R-script, but it does not work the same way in a R-markdown.
In this case I get the following error in the console and no log-file gets generated.
Error in globalCallingHandlers(error = function(m) { :
should not be called with handlers on the stack
Now if I have the same lines of code but instead in just a regular .R script file the actual log files gets generated and the error I am expecting also is recorded in the log file created.
INFO [2022-07-26 11:26:51] Logging starting:
INFO [2022-07-26 11:26:52] Starting Function: -get_data()-. File: -data.R-
ERROR [2022-07-26 11:26:59] nanodbc/nanodbc.cpp...
I know for certain that the cause of this issue is when log_errors() is called in the function configuration_logger() that is used in init_logger(). I tried removing this line of code and the log files get generated in both the .Rmd rmarkdown and .R script when calling the same function, but then any errors occurring do not get recorded in the log file but they are just printed in the console instead.
Anyone knows why this is occurring in r-markdowns only when log_errors() is initialized and if there is a possible solution to it since I would like to record any errors that might occur in my function in the log file that gets created when using r-markdowns.
I created a function to initialize logging using logger package and to save the logs entries in a temporary file in the tempdir() given by R.
The function above initializes the log and I am calling this
mypackage::init_logger()
in another functionmypackage::get_data(client, dimensions, metrics, start_date, end_date, ...)
where I want to capture certain information as well as any errors that might occur, therefore thelog_errors()
is crucial in order to debug if anything goes wrong. Everything works fine if this function is called in a regular R-script, but it does not work the same way in a R-markdown.If I force an error in a markdown:
In this case I get the following error in the console and no log-file gets generated.
Now if I have the same lines of code but instead in just a regular .R script file the actual log files gets generated and the error I am expecting also is recorded in the log file created.
I know for certain that the cause of this issue is when log_errors() is called in the function configuration_logger() that is used in init_logger(). I tried removing this line of code and the log files get generated in both the .Rmd rmarkdown and .R script when calling the same function, but then any errors occurring do not get recorded in the log file but they are just printed in the console instead.
Anyone knows why this is occurring in r-markdowns only when log_errors() is initialized and if there is a possible solution to it since I would like to record any errors that might occur in my function in the log file that gets created when using r-markdowns.