[Logging-commits] r88 - in pkg: R inst/unitTest

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 3 15:56:53 CEST 2011


Author: mariotomo
Date: 2011-08-03 15:56:53 +0200 (Wed, 03 Aug 2011)
New Revision: 88

Modified:
   pkg/R/logger.R
   pkg/inst/unitTest/runit.handlers.R
Log:
comparing the documentation with the current behaviour, adding tests, correcting differences.


Modified: pkg/R/logger.R
===================================================================
--- pkg/R/logger.R	2011-08-03 13:34:36 UTC (rev 87)
+++ pkg/R/logger.R	2011-08-03 13:56:53 UTC (rev 88)
@@ -123,7 +123,21 @@
 addHandler <- function(handler, ..., logger='') {
   if(is.character(logger))
     logger <- getLogger(logger)
-  logger$addHandler(handler, ...)
+
+  ## this part has to be repeated here otherwise the called function
+  ## will deparse the argument to 'handler', the formal name given
+  ## here to the parameter
+  if(is.character(handler)) {
+    params <- list(...)
+    if('action' %in% names(params))
+      action <- params[['action']]
+    else
+      action <- params[[1]]
+  } else {
+    action <- handler
+    handler <- deparse(substitute(handler))
+  }
+  logger$addHandler(handler, action, ...)
 }
 
 removeHandler <- function(handler, logger='') {

Modified: pkg/inst/unitTest/runit.handlers.R
===================================================================
--- pkg/inst/unitTest/runit.handlers.R	2011-08-03 13:34:36 UTC (rev 87)
+++ pkg/inst/unitTest/runit.handlers.R	2011-08-03 13:56:53 UTC (rev 88)
@@ -4,11 +4,30 @@
 # $Id: runit.data.interaction.R 86 2011-08-03 13:16:48Z mariotomo $
 
 test.looksForHandlersInRootLogger <- function() {
+  logReset()
   basicConfig()
   checkIdentical(getLogger()[['handlers']][[1]], getHandler('basic.stdout'))
 }
 
 test.lookingForHandlersInObject <- function() {
+  logReset()
   basicConfig()
   checkIdentical(getLogger()[['handlers']][[1]], getLogger()$getHandler('basic.stdout'))
 }
+
+test.addingANewHandler <- function() {
+  logReset()
+  basicConfig()
+  addHandler(writeToConsole)
+  checkEquals(2, length(with(getLogger(), names(handlers))))
+  checkTrue('writeToConsole' %in% with(getLogger(), names(handlers)))
+}
+
+test.removingOneHandlerByName <- function() {
+  logReset()
+  basicConfig()
+  addHandler(writeToConsole)
+  removeHandler('writeToConsole')
+  checkEquals(1, length(with(getLogger(), names(handlers))))
+  checkTrue(!'writeToConsole' %in% with(getLogger(), names(handlers)))
+}



More information about the Logging-commits mailing list