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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Oct 18 11:14:14 CEST 2010


Author: mariotomo
Date: 2010-10-18 11:14:14 +0200 (Mon, 18 Oct 2010)
New Revision: 48

Modified:
   pkg/DESCRIPTION
   pkg/R/logger.R
   pkg/inst/unitTest/runit.data.interaction.R
Log:
#1155


Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2010-10-16 07:45:49 UTC (rev 47)
+++ pkg/DESCRIPTION	2010-10-18 09:14:14 UTC (rev 48)
@@ -1,5 +1,5 @@
 Package: logging
-Version: 0.4-47
+Version: 0.4-48
 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	2010-10-16 07:45:49 UTC (rev 47)
+++ pkg/R/logger.R	2010-10-18 09:14:14 UTC (rev 48)
@@ -66,18 +66,22 @@
     parts <- strsplit(logger, '.', fixed=TRUE)[[1]] # split the name on the '.'
     removed <- parts[-length(parts)] # except the last item
     parent <- paste(removed, collapse='.')
-    levellog(record, logger=parent)
+    .logrecord(record, logger=parent)
   }
-  invisible()
+  invisible(TRUE)
 }
 
 ## main log function, used by all other ones
 ## (entry points for messages)
-levellog <- function(level, msg, ..., logger=NA)
+levellog <- function(level, msg, ..., logger='')
 {
-  if (!is.character(logger))
-    logger <- ''
+  ## does the logger just drop the record?
+  config <- getLogger(logger)
+  if (level < config$level) 
+    return(invisible(FALSE))
 
+  ## fine, we create the record and pass it to all handlers attached to the
+  ## loggers from here up to the root.
   record <- list()
 
   if (length(list(...)) > 0)
@@ -91,6 +95,7 @@
   if(is.na(record$levelname))
     record$levelname <- paste("NumericLevel(", level, ")", sep='')
 
+  ## action is taken in private function.
   .logrecord(record, logger)
 }
 

Modified: pkg/inst/unitTest/runit.data.interaction.R
===================================================================
--- pkg/inst/unitTest/runit.data.interaction.R	2010-10-16 07:45:49 UTC (rev 47)
+++ pkg/inst/unitTest/runit.data.interaction.R	2010-10-18 09:14:14 UTC (rev 48)
@@ -59,3 +59,71 @@
   expect <- logging:::loglevels['DEBUG']
   checkEquals(rootLogger[['level']], expect)
 }
+
+logged <- NULL
+mockAction <- function(msg, handler) {
+  logged <<- c(logged, msg)
+}
+
+test.recordIsEmitted.rootToRoot <- function() {
+  logReset()
+  addHandler(mockAction)
+  logged <<- NULL
+  logdebug('test')
+  loginfo('test')
+  logerror('test')
+  checkEquals(length(logged), 2)
+}
+
+test.recordIsEmitted.tooDeep <- function() {
+  logReset()
+  addHandler(mockAction, logger='too.deep')
+  logged <<- NULL
+  logdebug('test')
+  loginfo('test')
+  logerror('test')
+  checkEquals(length(logged), 0)
+}
+
+test.recordIsEmitted.unrelated <- function() {
+  logReset()
+  addHandler(mockAction, logger='too.deep')
+  logged <<- NULL
+  logdebug('test', logger='other.branch')
+  loginfo('test', logger='other.branch')
+  logerror('test', logger='other.branch')
+  checkEquals(length(logged), 0)
+}
+
+test.recordIsEmitted.deepToRoot <- function() {
+  logReset()
+  addHandler(mockAction, logger='')
+  logged <<- NULL
+  logdebug('test', logger='other.branch')
+  loginfo('test', logger='other.branch')
+  logerror('test', logger='other.branch')
+  checkEquals(length(logged), 2)
+}
+
+test.recordIsEmitted.deepToRoot.DI.dropped <- function() {
+  logReset()
+  addHandler(mockAction, level='DEBUG', logger='')
+  logged <<- NULL
+  setLevel('other.branch', 'INFO')
+  logdebug('test', logger='other.branch')
+  loginfo('test', logger='other.branch')
+  logerror('test', logger='other.branch')
+  checkEquals(length(logged), 2)
+}
+
+test.recordIsEmitted.deepToRoot.DD.passed <- function() {
+  logReset()
+  addHandler(mockAction, level='DEBUG', logger='')
+  logged <<- NULL
+  setLevel('DEBUG', 'other.branch')
+  setLevel('DEBUG', '')
+  logdebug('test', logger='other.branch')
+  loginfo('test', logger='other.branch')
+  logerror('test', logger='other.branch')
+  checkEquals(length(logged), 3)
+}



More information about the Logging-commits mailing list