[Logging-commits] r47 - in pkg: . R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Oct 16 09:45:49 CEST 2010
Author: mariotomo
Date: 2010-10-16 09:45:49 +0200 (Sat, 16 Oct 2010)
New Revision: 47
Modified:
pkg/DESCRIPTION
pkg/R/logger.R
Log:
possibly solving #1155
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2010-10-04 07:36:11 UTC (rev 46)
+++ pkg/DESCRIPTION 2010-10-16 07:45:49 UTC (rev 47)
@@ -1,5 +1,5 @@
Package: logging
-Version: 0.4-42
+Version: 0.4-47
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-04 07:36:11 UTC (rev 46)
+++ pkg/R/logger.R 2010-10-16 07:45:49 UTC (rev 47)
@@ -49,94 +49,94 @@
value
}
+.logrecord <- function(record, logger)
+{
+ ## get the logger of which we have the name.
+ config <- getLogger(logger)
+
+ if (record$level >= config$level)
+ for (handler in config[['handlers']])
+ if (record$level >= with(handler, level)) {
+ action <- with(handler, action)
+ formatter <- with(handler, formatter)
+ action(formatter(record), handler)
+ }
+
+ if(logger != '') {
+ 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)
+ }
+ invisible()
+}
+
## main log function, used by all other ones
## (entry points for messages)
-levellog <- function(level, msg, ..., logger=NA, sourcelogger='')
+levellog <- function(level, msg, ..., logger=NA)
{
- if (!is.character(sourcelogger))
- sourcelogger <- ''
if (!is.character(logger))
- logger <- sourcelogger
- ## get the logger of which we have the name.
- config <- getLogger(logger)
- if (level < config$level) return(invisible())
+ logger <- ''
- ## what is the record to be logged?
record <- list()
- if (length(list(...)) > 0) msg <- sprintf(msg, ...)
+ if (length(list(...)) > 0)
+ msg <- sprintf(msg, ...)
record$msg <- msg
record$timestamp <- sprintf("%s", Sys.time())
- record$logger <- sourcelogger
+ record$logger <- logger
record$level <- namedLevel(level)
record$levelname <- names(which(loglevels == level)[1])
if(is.na(record$levelname))
record$levelname <- paste("NumericLevel(", level, ")", sep='')
- ## invoke the action of all handlers associated to logger
- for (handler in config[['handlers']]) {
- if (level >= with(handler, level)) {
- action <- with(handler, action)
- formatter <- with(handler, formatter)
- action(formatter(record), handler)
- }
- }
-
- ## if not at root level, check the parent logger
- if(logger != ''){
- parts <- strsplit(logger, '.', fixed=TRUE)[[1]] # split the name on the '.'
- removed <- parts[-length(parts)] # except the last item
- parent <- paste(removed, collapse='.')
- levellog(level, msg, ..., logger=parent, sourcelogger=sourcelogger)
- }
-
- invisible()
+ .logrecord(record, logger)
}
## using log
logdebug <- function(msg, ..., logger='')
{
- levellog(loglevels[['DEBUG']], msg, ..., sourcelogger=logger)
+ levellog(loglevels[['DEBUG']], msg, ..., logger=logger)
invisible()
}
logfinest <- function(msg, ..., logger='')
{
- levellog(loglevels['FINEST'], msg, ..., sourcelogger=logger)
+ levellog(loglevels['FINEST'], msg, ..., logger=logger)
invisible()
}
logfiner <- function(msg, ..., logger='')
{
- levellog(loglevels['FINER'], msg, ..., sourcelogger=logger)
+ levellog(loglevels['FINER'], msg, ..., logger=logger)
invisible()
}
logfine <- function(msg, ..., logger='')
{
- levellog(loglevels[['FINE']], msg, ..., sourcelogger=logger)
+ levellog(loglevels[['FINE']], msg, ..., logger=logger)
invisible()
}
## using log
loginfo <- function(msg, ..., logger='')
{
- levellog(loglevels['INFO'], msg, ..., sourcelogger=logger)
+ levellog(loglevels['INFO'], msg, ..., logger=logger)
invisible()
}
## using log
logwarn <- function(msg, ..., logger='')
{
- levellog(loglevels['WARN'], msg, ..., sourcelogger=logger)
+ levellog(loglevels['WARN'], msg, ..., logger=logger)
invisible()
}
## using log
logerror <- function(msg, ..., logger='')
{
- levellog(loglevels['ERROR'], msg, ..., sourcelogger=logger)
+ levellog(loglevels['ERROR'], msg, ..., logger=logger)
invisible()
}
More information about the Logging-commits
mailing list