3 log_clear <- function() {
4 assign('log_messages',list(),envir=.GlobalEnv)
7 log_add <- function(text,print=T) {
10 "[",strftime(Sys.time(),format="%H:%M:%OS6"),"] ",text))
12 assign('log_messages',c(log_messages, text),envir=.GlobalEnv)
15 log_retrieve <- function() {
19 notice <- function(...) {
20 log_add(paste('N:',...))
23 warn <- function(...) {
24 log_add(paste('W:',...))
27 error <- function(...) {
28 log_add(paste('E:',...))
31 fail <- function(...) {
32 txt <- paste('E:',...)
37 log_system <- function(...) {
38 r <- try((function() {
39 # pipe() does not appear useful here, since
40 # we want the return value!
41 # XXX: doesn't work with ; or | !
42 tmp <- tempfile('log_system')
45 # unfortunately this destroys ret
46 #cmd <- paste(cmd,'2>&1','| tee',tmp)
47 cmd <- paste(cmd,'>',tmp,'2>&1')
50 output <- readLines(f)
53 return(list(ret,output))
55 if (inherits(r,'try-error')) {
56 fail('system failed on:',paste(...))
58 log_add(paste('C:',...))
59 for (line in r[[2]]) {
60 if (!length(grep('^[WENI]:',line))) {
61 line = paste('I:',line)
63 log_add(line) #,print=F)