Mercurial > repos > prog > lcmsmatching
comparison BiodbLogger.R @ 2:20d69a062da3 draft
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
author | prog |
---|---|
date | Thu, 02 Mar 2017 08:55:00 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:253d531a0193 | 2:20d69a062da3 |
---|---|
1 # vi: fdm=marker | |
2 | |
3 ########################## | |
4 # CLASS DECLARATION {{{1 # | |
5 ########################## | |
6 | |
7 BiodbLogger <- methods::setRefClass("BiodbLogger", contains = 'BiodbObserver', fields = list(.verbose.level = 'integer', .debug.level = 'integer', .file = 'ANY', .fail.on.error = 'logical', .signal.warnings = 'logical')) | |
8 | |
9 #################### | |
10 # CONSTRUCTOR {{{1 # | |
11 #################### | |
12 | |
13 BiodbLogger$methods( initialize = function(verbose.level = 1, debug.level = 1, file = NULL, ...) { | |
14 | |
15 .verbose.level <<- if ( ! is.null(verbose.level) && ! is.na(verbose.level)) verbose.level else 1 | |
16 .debug.level <<- if ( ! is.null(debug.level) && ! is.na(debug.level)) debug.level else 1 | |
17 .file <<- if ( ! is.null(file) && ! is.na(file)) file else stderr() | |
18 .fail.on.error <<- TRUE | |
19 .signal.warnings <<- TRUE | |
20 | |
21 callSuper(...) | |
22 }) | |
23 | |
24 ################ | |
25 # MESSAGE {{{1 # | |
26 ################ | |
27 | |
28 BiodbLogger$methods( message = function(type = MSG.INFO, msg, level = 1) { | |
29 type %in% biodb::MSG.TYPES || .self$message(biodb::MSG.ERROR, paste0("Unknown message type ", type, ".")) | |
30 | |
31 display = TRUE | |
32 if (type == biodb::MSG.INFO && .self$.verbose.level < level) | |
33 display = FALSE | |
34 if (type == biodb::MSG.DEBUG && .self$.debug.level < level) | |
35 display = FALSE | |
36 | |
37 if (display) | |
38 cat(type, ': ', msg, "\n", sep = '', file = .self$.file) | |
39 | |
40 # Raise error | |
41 if (type == biodb::MSG.ERROR && .self$.fail.on.error) | |
42 stop(msg) | |
43 | |
44 # Raise warning | |
45 if (type == biodb::MSG.WARNING && .self$.signal.warnings) | |
46 warning(msg) | |
47 }) |