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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 5 10:13:27 CEST 2011


Author: mariotomo
Date: 2011-09-05 10:13:27 +0200 (Mon, 05 Sep 2011)
New Revision: 92

Modified:
   pkg/DESCRIPTION
   pkg/R/logger.R
   pkg/R/oo.R
   pkg/inst/unitTest/runit.handlers.R
Log:
fixing "missing action" problem in handlers defined with `addHandler` function.  `$addHandler` method was unaffected.


Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2011-08-04 09:05:21 UTC (rev 91)
+++ pkg/DESCRIPTION	2011-09-05 08:13:27 UTC (rev 92)
@@ -1,5 +1,5 @@
 Package: logging
-Version: 0.6-85
+Version: 0.6-92
 Date: 2010-06-17
 Title: a tentative logging package
 Author: Mario Frasca <mariotomo at gmail.com>

Modified: pkg/R/logger.R
===================================================================
--- pkg/R/logger.R	2011-08-04 09:05:21 UTC (rev 91)
+++ pkg/R/logger.R	2011-09-05 08:13:27 UTC (rev 92)
@@ -128,16 +128,10 @@
   ## 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]]
+    logger$addHandler(handler, ...)
   } else {
-    action <- handler
-    handler <- deparse(substitute(handler))
+    logger$addHandler(handler=deparse(substitute(handler)), action=handler, ...)
   }
-  logger$addHandler(handler, action, ...)
 }
 
 removeHandler <- function(handler, logger='') {

Modified: pkg/R/oo.R
===================================================================
--- pkg/R/oo.R	2011-08-04 09:05:21 UTC (rev 91)
+++ pkg/R/oo.R	2011-09-05 08:13:27 UTC (rev 92)
@@ -116,7 +116,7 @@
                               assign('action', params[[1]], handlerEnv)
                           } else  {
                             ## first parameter is handler action, from which we extract the name
-                            assign('action', handler, handlerEnv)
+                            updateOptions.environment(handlerEnv, action=handler)
                             handlerName <- deparse(substitute(handler))
                           }
                           updateOptions.environment(handlerEnv, ...)

Modified: pkg/inst/unitTest/runit.handlers.R
===================================================================
--- pkg/inst/unitTest/runit.handlers.R	2011-08-04 09:05:21 UTC (rev 91)
+++ pkg/inst/unitTest/runit.handlers.R	2011-09-05 08:13:27 UTC (rev 92)
@@ -31,3 +31,39 @@
   checkEquals(1, length(with(getLogger(), names(handlers))))
   checkTrue(!'writeToConsole' %in% with(getLogger(), names(handlers)))
 }
+
+test.fileName <- file.path(tempdir(), c('1', '2', '3'))
+
+.setUp <- function() {
+}
+
+.tearDown <- function() {
+  file.remove(test.fileName)
+}
+
+test.loggingToFile <- function() {
+  logReset()
+  file.remove(test.fileName)
+
+  getLogger()$setLevel('FINEST')
+  addHandler(writeToFile, file=test.fileName, level='DEBUG')
+  checkEquals(c("writeToFile"), with(getLogger(), names(handlers)))
+  loginfo('test %d', 1)
+  logdebug('test %d', 2)
+  logwarn('test %d', 3)
+  logfinest('test %d', 4)
+}
+
+test.loggingToFile.oo <- function() {
+  logReset()
+  file.remove(test.fileName)
+
+  log <- getLogger()
+  log$setLevel('FINEST')
+  log$addHandler(writeToFile, file=test.fileName, level='DEBUG')
+  checkEquals(c("writeToFile"), with(log, names(handlers)))
+  log$info('test %d', 1)
+  log$debug('test %d', 2)
+  log$warn('test %d', 3)
+  log$finest('test %d', 4)
+}



More information about the Logging-commits mailing list