R/ldap4R_logger.R

#' ldap4RLogger
#'
#' @docType class
#' @export
#' @keywords logger
#' @return Object of \code{\link{R6Class}} for modelling a simple logger
#' @format \code{\link{R6Class}} object.
#'
#' @section Abstract Methods:
#' \describe{
#'  \item{\code{INFO(text)}}{
#'    Logger to report information. Used internally
#'  }
#'  \item{\code{WARN(text)}}{
#'    Logger to report warnings. Used internally
#'  }
#'  \item{\code{ERROR(text)}}{
#'    Logger to report errors. Used internally
#'  }
#' }
#' 
#' @note Logger class used internally by ldap4R
#'
ldap4RLogger <-  R6Class("ldap4RLogger",
 public = list(
   #logger
   verbose.info = FALSE,
   verbose.debug = FALSE,
   loggerType = NULL,
   logger = function(type, text){
     if(self$verbose.info){
      cat(sprintf("[ldap4R][%s] %s - %s \n", type, self$getClassName(), text))
     }
   },
   INFO = function(text){self$logger("INFO", text)},
   WARN = function(text){self$logger("WARN", text)},
   ERROR = function(text){self$logger("ERROR", text)},
   
   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
      }
      }
     }
   },
   
   #getClassName
   getClassName = function(){
     return(class(self)[1])
   },
   
   #getClass
   getClass = function(){
     class <- eval(parse(text=self$getClassName()))
     return(class)
   }
   
  )
)
eblondel/ldap4R documentation built on Nov. 4, 2019, 11:28 a.m.