I'm trying to understand the best way to log errors in an A project. I have a project where I'm ingesting data from an API and pushing a cloud database and I want to be able to create/monitor logs.
I found this tutorial that uses a combination of tryCatch()
and futile.logger
R package. In the tutorial, he creates a function that would generate an error and according to him, the error will generate a log file. However when I run the code, the error appears in my console but no log file is generated. See code below -
library(tidyverse)
library(futile.logger)
library(tryCatchLog)
# Function to run
get_test_function <- function() {
print("test")
log("test")
}
# Trycatch configuration
options(keep.source = TRUE)
options("tryCatchLog.write.error.dump.file" = TRUE)
flog.appender(appender.file("error.log"))
flog.threshold("ERROR")
# Run function
tryCatch(get_test_function())
- If this is an efficient way to log errors, what am I doing wrong that the log file is not generated.
- If there is a better way to achieve this, please do kindly share.