[Logging-commits] r18 - pkg pkg/R pkg/inst/RUnit pkg/man www
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Apr 8 11:44:43 CEST 2010
Author: mariotomo
Date: 2010-04-08 11:44:43 +0200 (Thu, 08 Apr 2010)
New Revision: 18
Added:
pkg/man/getHandler.Rd
Modified:
pkg/DESCRIPTION
pkg/NAMESPACE
pkg/R/logger.R
pkg/inst/RUnit/runit.data.interaction.R
pkg/man/basicConfig.Rd
pkg/man/log.Rd
pkg/man/logging-internal.Rd
www/sample_session.html
Log:
matching to the documentation on the webpage http://logging.r-forge.r-project.org/sample_session.html
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2010-04-08 06:04:24 UTC (rev 17)
+++ pkg/DESCRIPTION 2010-04-08 09:44:43 UTC (rev 18)
@@ -1,5 +1,5 @@
Package: logging
-Version: 0.4-13
+Version: 0.4-18
Date: 2010-01-14
Title: a tentative logging package
Author: Mario Frasca <mariotomo at gmail.com>
Modified: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE 2010-04-08 06:04:24 UTC (rev 17)
+++ pkg/NAMESPACE 2010-04-08 09:44:43 UTC (rev 18)
@@ -26,6 +26,6 @@
writeToFile,
writeToConsole,
updateOptions.environment,
- updateOptions
-
+ updateOptions,
+ logReset
)
Modified: pkg/R/logger.R
===================================================================
--- pkg/R/logger.R 2010-04-08 06:04:24 UTC (rev 17)
+++ pkg/R/logger.R 2010-04-08 09:44:43 UTC (rev 18)
@@ -33,8 +33,10 @@
## main log function, used by all other ones
## (entry points for messages)
-levellog <- function(level, msg, ..., logger='')
+levellog <- function(level, msg, ..., logger=NA, sourcelogger='')
{
+ if (is.na(logger))
+ logger <- sourcelogger
## get the logger of which we have the name.
config <- getLogger(logger)
if (level < config$level) return(invisible())
@@ -46,7 +48,7 @@
record$msg <- msg
record$timestamp <- sprintf("%s", Sys.time())
- record$logger <- logger
+ record$logger <- sourcelogger
record$level <- level
record$levelname <- names(which(loglevels == level)[1])
if(is.na(record$levelname))
@@ -66,7 +68,7 @@
parts <- strsplit(logger, '\\.')[[1]] # split the name on the '.'
removed <- parts[-length(parts)] # except the last item
parent <- paste(removed, collapse='.')
- levellog(level, msg, ..., logger=parent)
+ levellog(level, msg, ..., logger=parent, sourcelogger=sourcelogger)
}
invisible()
@@ -75,46 +77,46 @@
## using log
logdebug <- function(msg, ..., logger='')
{
- levellog(loglevels[['DEBUG']], msg, ..., logger=logger)
+ levellog(loglevels[['DEBUG']], msg, ..., sourcelogger=logger)
invisible()
}
logfinest <- function(msg, ..., logger='')
{
- levellog(loglevels['FINEST'], msg, ..., logger=logger)
+ levellog(loglevels['FINEST'], msg, ..., sourcelogger=logger)
invisible()
}
logfiner <- function(msg, ..., logger='')
{
- levellog(loglevels['FINER'], msg, ..., logger=logger)
+ levellog(loglevels['FINER'], msg, ..., sourcelogger=logger)
invisible()
}
logfine <- function(msg, ..., logger='')
{
- levellog(loglevels[['FINE']], msg, ..., logger=logger)
+ levellog(loglevels[['FINE']], msg, ..., sourcelogger=logger)
invisible()
}
## using log
loginfo <- function(msg, ..., logger='')
{
- levellog(loglevels['INFO'], msg, ..., logger=logger)
+ levellog(loglevels['INFO'], msg, ..., sourcelogger=logger)
invisible()
}
## using log
logwarn <- function(msg, ..., logger='')
{
- levellog(loglevels['WARN'], msg, ..., logger=logger)
+ levellog(loglevels['WARN'], msg, ..., sourcelogger=logger)
invisible()
}
## using log
logerror <- function(msg, ..., logger='')
{
- levellog(loglevels['ERROR'], msg, ..., logger=logger)
+ levellog(loglevels['ERROR'], msg, ..., sourcelogger=logger)
invisible()
}
@@ -186,7 +188,7 @@
writeToConsole <- function(msg, handler)
{
- cat(msg)
+ cat(paste(msg, '\n', sep=''))
}
writeToFile <- function(msg, handler)
@@ -196,7 +198,7 @@
cat("handler with writeToFile 'action' must have a 'file' element.\n")
return()
}
- cat(msg, file=handler$file, append=TRUE)
+ cat(paste(msg, '\n', sep=''), file=handler$file, append=TRUE)
}
#################################################################################
@@ -204,7 +206,7 @@
## the single predefined formatter
defaultFormat <- function(record) {
- paste(record$timestamp, record$levelname, record$msg, '\n')
+ text <- paste(record$timestamp, paste(record$levelname, record$logger, record$msg, sep=':'))
}
#################################################################################
@@ -280,9 +282,19 @@
#################################################################################
-## initialize the module
+logReset <- function() {
+ ## reinizialize the whole logging system
-## The logger options manager
+ ## remove all content from the logging environment
+ rm(list=ls(logging.options), envir=logging.options)
+
+ ## create the root logger
+ getLogger('', handlers=NULL, level=0)
+ invisible()
+}
+
+## create the logging environment
logging.options <- new.env()
-getLogger('', handlers=NULL, level=0)
+## initialize the module
+logReset()
Modified: pkg/inst/RUnit/runit.data.interaction.R
===================================================================
--- pkg/inst/RUnit/runit.data.interaction.R 2010-04-08 06:04:24 UTC (rev 17)
+++ pkg/inst/RUnit/runit.data.interaction.R 2010-04-08 09:44:43 UTC (rev 18)
@@ -46,7 +46,7 @@
test.canSetLoggerLevelByNamedValue <- function() {
basicConfig()
- setLevel('', logging:::loglevels['DEBUG'])
+ setLevel(logging:::loglevels['DEBUG'], '')
rootLogger <- getLogger('')
expect <- logging:::loglevels['DEBUG']
checkEquals(rootLogger[['level']], expect)
@@ -54,7 +54,7 @@
test.canSetLoggerLevelByName <- function() {
basicConfig()
- setLevel('', 'DEBUG')
+ setLevel('DEBUG', '')
rootLogger <- getLogger('')
expect <- logging:::loglevels['DEBUG']
checkEquals(rootLogger[['level']], expect)
Modified: pkg/man/basicConfig.Rd
===================================================================
--- pkg/man/basicConfig.Rd 2010-04-08 06:04:24 UTC (rev 17)
+++ pkg/man/basicConfig.Rd 2010-04-08 09:44:43 UTC (rev 18)
@@ -3,6 +3,7 @@
\name{basicConfig}
\alias{basicConfig}
+\alias{logReset}
\title{bootstrapping the logging package}
\description{
@@ -12,10 +13,13 @@
}
\usage{
basicConfig()
+logReset()
}
\examples{
library(logging)
basicConfig()
logdebug("not shown, basic is INFO")
logwarn("shown and timestamped")
+logReset()
+logwarn("not shown, as no handlers are present after a reset")
}
\ No newline at end of file
Added: pkg/man/getHandler.Rd
===================================================================
--- pkg/man/getHandler.Rd (rev 0)
+++ pkg/man/getHandler.Rd 2010-04-08 09:44:43 UTC (rev 18)
@@ -0,0 +1,25 @@
+% File src/R/man/getHandler.Rd
+% $Id: getLogger.Rd 11 2010-04-03 18:54:20Z mariotomo $
+
+\name{getHandler}
+\alias{getHandler}
+\alias{getHandler.character}
+\alias{getHandler.default}
+\title{retrieves a handler from a logger.}
+\description{
+
+ handlers are not uniquely identified by their name. only within the
+ logger to which they are attached is their name unique. this function
+ is here to allow you grab a handler from a logger so you can examine
+ and alter it.
+
+ typical use of this function is in setLevel(newLevel, getHandler(...)).
+
+}
+\usage{
+getHandler(handler, logger='')
+}
+\arguments{
+ \item{handler}{the name of the handler, or its action.}
+ \item{logger}{optional: the name of the logger. defaults to the root logger.}
+}
Property changes on: pkg/man/getHandler.Rd
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: pkg/man/log.Rd
===================================================================
--- pkg/man/log.Rd 2010-04-08 06:04:24 UTC (rev 17)
+++ pkg/man/log.Rd 2010-04-08 09:44:43 UTC (rev 18)
@@ -1,8 +1,7 @@
% File src/R/man/log.Rd
% $Id$
-\name{levellog}
-\alias{levellog}
+\name{loginfo}
\alias{logfinest}
\alias{logfiner}
\alias{logfine}
@@ -24,8 +23,6 @@
loginfo(msg, ..., logger='')
logwarn(msg, ..., logger='')
logerror(msg, ..., logger='')
-
-levellog(level, msg, ..., logger='')
}
\arguments{
\item{msg}{the textual message to be output, or the format for the
@@ -33,6 +30,4 @@
\item{...}{if present, msg is interpreted as a format and the
... values are passed to it to form the actual message.}
\item{logger}{the name of the logger to which we pass the record}
-
- \item{level}{the explicit numeric level of the log record}
}
Modified: pkg/man/logging-internal.Rd
===================================================================
--- pkg/man/logging-internal.Rd 2010-04-08 06:04:24 UTC (rev 17)
+++ pkg/man/logging-internal.Rd 2010-04-08 09:44:43 UTC (rev 18)
@@ -10,4 +10,5 @@
\alias{SVNVERSION}
\alias{SVNDATE}
\alias{updateOptions}
-\alias{updateOptions.environment}
\ No newline at end of file
+\alias{updateOptions.environment}
+\alias{levellog}
Modified: www/sample_session.html
===================================================================
--- www/sample_session.html 2010-04-08 06:04:24 UTC (rev 17)
+++ www/sample_session.html 2010-04-08 09:44:43 UTC (rev 18)
@@ -23,9 +23,9 @@
R> with(getLogger(), names(handlers))
[1] "basic.stdout"
R> loginfo('does it work?')
-2010-04-07 11:39:49 INFO does it work?
+2010-04-08 11:28:35 INFO::does it work?
R> logwarn('%s %d', 'my name is', 5)
-2010-04-07 11:40:38 WARN my name is 5
+2010-04-08 11:28:48 WARN::my name is 5
R> logdebug('I am a silent child')
R>
</pre>
@@ -40,29 +40,30 @@
R> with(getLogger(), names(handlers))
[1] "basic.stdout" "writeToConsole"
R> loginfo('test')
-2010-04-07 11:31:06 INFO test
-2010-04-07 11:31:06 INFO test
+2010-04-07 11:31:06 INFO::test
+2010-04-07 11:31:06 INFO::test
R> logwarn('test')
-2010-04-07 11:31:15 WARN test
-2010-04-07 11:31:15 WARN test
+2010-04-07 11:31:15 WARN::test
+2010-04-07 11:31:15 WARN::test
R> removeHandler('writeToConsole')
R> logwarn('test')
-2010-04-07 11:32:37 WARN test
+2010-04-07 11:32:37 WARN::test
R>
</pre>
-<p>handlers are associated to a level. any logging record passing
-through a handler and having a level lower than the level of the
-handler is ignored. you can alter the level of a handler. this is
-what we do here: we alter the level of the default console handler
-'basic.stdout' to 30 (WARNING). by the way, also handlers are environments.</p>
+<p>handlers have a level associated to them. any logging record
+passing through a handler and having a level lower than the level of
+the handler is ignored. you can alter the level of a handler. this
+is what we do in the following lines: we alter the level of the
+default console handler 'basic.stdout' to 30 (WARNING). by the way,
+also handlers are environments.</p>
<pre>
R> addHandler(writeToConsole)
R> setLevel(30, getHandler('basic.stdout'))
R> loginfo('test')
R> logwarn('test')
-2010-04-07 15:17:40 WARN test
+2010-04-07 15:17:40 WARN::test
R> with(getHandler('basic.stdout'), level)
[1] 30
R>
@@ -72,7 +73,9 @@
<p>in the previous section we have worked -implicitly- with one
logger, the root logger. we can refer to it explicitly: its name is
-the empty string.</p>
+the empty string. this also explains that "::" in the messages sent
+to the console, between the first and the second ":" there's the name
+of the logger that is associated to the log record shown.</p>
<pre>
R> with(getLogger(logger=''), names(handlers))
@@ -89,22 +92,32 @@
their name is, within the logger, unique. also similarly than to
directories, all loggers have one parent, except the root logger that
has none. the name of the logger specifies the location of the logger
-in this hierarchy. an example will hopefully clarify. let's start
-from scratch, a brand new R session.</p>
+in this hierarchy. an example will hopefully clarify. </p>
+<p>let's start from scratch, either a brand new R session or by
+resetting the logging system.</p>
+
<pre>
-R> library(logging)
-R> addHandler(writeToConsole, logger='libro.romanzo.campanile')
+R> logReset()
+R> addHandler(writeToConsole, logger='libro.romanzo')
R> loginfo('chiarastella', logger='libro.romanzo.campanile')
-2010-04-07 17:08:59 INFO chiarastella
-R> loginfo('talking to the root logger')
+2010-04-08 11:18:59 INFO:libro.romanzo.campanile:chiarastella
+R> loginfo('memories of a survivor', logger='libro.romanzo.lessing')
+2010-04-08 11:22:06 INFO:libro.romanzo.lessing:memories of a survivor
+R> logwarn('talking to a upper level logger', logger='libro')
+R> logerror('talking to an unrelated logger', logger='rivista.cucina')
R>
</pre>
-if you define a logger by this name, all record you
+notice that loggers are automatically defined by the simple action of
+naming them. what happened above is that the handler we created,
+attached to the 'libro.romanzo' logger, only saw the records going to
+the loggers below its logger. all records going to upper level
+loggers or to unrelated loggers are not logged, regardless of the
+level.
<h5>logging to file</h5>
-<h5>formatting your log record</h5>
+<h5>formatting your log records</h5>
</body>
</html>
More information about the Logging-commits
mailing list