-
Notifications
You must be signed in to change notification settings - Fork 10
/
logging.R
executable file
·28 lines (22 loc) · 1.09 KB
/
logging.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
my.error.fun <- function() {
time.stamp <- date()
err.msg <- paste0( time.stamp, " -- DIED WITH ERROR:\n", geterrmessage())
cat(err.msg, file="output/logs/command_history.log", append=T)
q("no", status = 1, runLast = FALSE)
}
saveCommandLine <- function( logFile, args ) {
file.arg.name <- "--file="
script.name <- sub(file.arg.name, "", args[grep(file.arg.name, args)])
script.basename <- dirname(script.name)
args.positions <- grep("--args", args)
time.stamp <- date()
version <- system(paste0("git --git-dir ",script.basename,"/../.git --work-tree ",script.basename,"/../ describe --always --dirty --tags"), intern=T)
commandLine <- paste(c(script.name,tail(args, -1*args.positions)),collapse=' ')
message <- paste0("\n",time.stamp," -- SONAR ",version," run with command:\n\t",commandLine,"\n")
cat(message, file=logFile, append=T)
}
logSuccess <- function() {
time.stamp <- date()
success <- paste0( time.stamp, " -- Program finished successfully\n" )
cat(success, file="output/logs/command_history.log", append=T)
}