-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.R
38 lines (33 loc) · 1.09 KB
/
utils.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require(datimvalidation)
require(futile.logger)
options(shiny.maxRequestSize=20*1024^2)
config <- list(BASEURL = Sys.getenv("BASE_URL"),
log_path = Sys.getenv("LOG_PATH"))
#Try and create the log directory if it does not exist
if (!dir.exists(dirname(config$log_path))) {
tryCatch({
dir.create(dirname(config$log_path))
} ,
error = function(e) {
warning("Could not create log directory")
})
}
#Try and create the log file if it does not exist
if (!file.exists(config$log_path)) {
tryCatch({
file.create(config$log_path)
} ,
error = function(e) {
warning("Could not create log file")
})
}
#Finally, test for write permission to the file.
#Fallback to the console logger if all else fails
if ( file.access(config$log_path,mode = 2) == -1L ) {
warning("Cannot write to log file. Falling back to console")
flog.appender(futile.logger::appender.console())
} else
{
print(paste("About to use a file appender log at",config$log_path))
flog.appender(futile.logger::appender.file(config$log_path))
}