-
Notifications
You must be signed in to change notification settings - Fork 14
/
zen4R_logger.R
76 lines (67 loc) · 2.27 KB
/
zen4R_logger.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#' zen4RLogger
#'
#' @docType class
#' @export
#' @keywords logger
#' @return Object of \code{\link{R6Class}} for modelling a simple logger
#' @format \code{\link{R6Class}} object.
#'
#' @note Logger class used internally by zen4R
#'
zen4RLogger <- R6Class("zen4RLogger",
public = list(
#' @field verbose.info logger info status
verbose.info = FALSE,
#' @field verbose.debug logger debug status
verbose.debug = FALSE,
#' @field loggerType Logger type, either "INFO", "DEBUG" or NULL (if no logger)
loggerType = NULL,
#' @description internal logger function for the Zenodo manager
#' @param type logger message type, "INFO", "WARN", or "ERROR"
#' @param text log message
logger = function(type, text){
if(self$verbose.info){
cat(sprintf("[zen4R][%s] %s - %s \n", type, self$getClassName(), text))
}
},
#' @description internal INFO logger function
#' @param text log message
INFO = function(text){self$logger("INFO", text)},
#' @description internal WARN logger function
#' @param text log message
WARN = function(text){self$logger("WARN", text)},
#' @description internal ERROR logger function
#' @param text log message
ERROR = function(text){self$logger("ERROR", text)},
#' @description initialize the Zenodo logger
#' @param logger logger type NULL, 'INFO', or 'DEBUG'
initialize = function(logger = NULL){
#logger
if(!missing(logger)){
if(!is.null(logger)){
self$loggerType <- toupper(logger)
if(!(self$loggerType %in% c("INFO","DEBUG"))){
stop(sprintf("Unknown logger type '%s", logger))
}
if(self$loggerType == "INFO"){
self$verbose.info = TRUE
}else if(self$loggerType == "DEBUG"){
self$verbose.info = TRUE
self$verbose.debug = TRUE
}
}
}
},
#'@description Get object class name
#'@return the class name, object of class \code{character}
getClassName = function(){
return(class(self)[1])
},
#'@description Get object class
#'@return the class, object of class \code{R6}
getClass = function(){
class <- eval(parse(text=self$getClassName()))
return(class)
}
)
)