[Logging-commits] r22 - pkg/R www
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Apr 8 14:51:47 CEST 2010
Author: mariotomo
Date: 2010-04-08 14:51:47 +0200 (Thu, 08 Apr 2010)
New Revision: 22
Modified:
pkg/R/logger.R
www/sample_session.html
Log:
makes sure levels are whenever possible named.
better typesetting.
Modified: pkg/R/logger.R
===================================================================
--- pkg/R/logger.R 2010-04-08 11:37:57 UTC (rev 21)
+++ pkg/R/logger.R 2010-04-08 12:51:47 UTC (rev 22)
@@ -31,6 +31,15 @@
loglevels <- c(0, 1, 4, 7, 10, 20, 30, 40, 50, 50)
names(loglevels) <- c('NOTSET', 'FINEST', 'FINER', 'FINE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL', 'FATAL')
+namedLevel <- function(value) {
+ if(is.null(names(value))) {
+ position <- which(loglevels == value)
+ if(length(position) == 1)
+ value = loglevels[position]
+ }
+ value
+}
+
## main log function, used by all other ones
## (entry points for messages)
levellog <- function(level, msg, ..., logger=NA, sourcelogger='')
@@ -49,7 +58,7 @@
record$timestamp <- sprintf("%s", Sys.time())
record$logger <- sourcelogger
- record$level <- level
+ record$level <- namedLevel(level)
record$levelname <- names(which(loglevels == level)[1])
if(is.na(record$levelname))
record$levelname <- paste("NumericLevel(", level, ")", sep='')
@@ -164,6 +173,7 @@
}
setLevel.numeric <- function(level, container='') {
+ level <- namedLevel(level)
updateOptions(container, level=level)
}
@@ -237,7 +247,7 @@
{
name <- handler # parameter 'handler' identifies the name
handler <- new.env()
- assign('level', level, handler)
+ assign('level', namedLevel(level), handler)
assign('action', action, handler)
assign('formatter', formatter, handler)
handlers <- with(getLogger(logger), handlers)
Modified: www/sample_session.html
===================================================================
--- www/sample_session.html 2010-04-08 11:37:57 UTC (rev 21)
+++ www/sample_session.html 2010-04-08 12:51:47 UTC (rev 22)
@@ -18,7 +18,11 @@
font-weight: normal!important;
}
user { font-weight: bold }
-h3, h4, p { font-family: helvetica, sans-serif } -->
+h3, h4, p { font-family: helvetica, sans-serif;}
+p { line-height: 20pt;
+ margin: 0 5em 6pt 0;
+}
+-->
</style>
</head>
<body>
@@ -28,6 +32,12 @@
and expect from this library. this text is directed to scripts
authors who want to be able to log the activity of their programs.</p>
+<p>this library attempts to be as compatible as possible (that is: as
+it was conceivable to the author) to the
+standard <a href="http://docs.python.org/library/logging.html">Python
+logging</a> library. if you are accustomed to that logging library,
+this one will look familiar to you.</p>
+
<h4>the basics</h4>
<p>in this session we work with one single logger, the root logger, and we use only console handlers</p>
@@ -44,7 +54,7 @@
to inspect them. after this basic configuration, our logger has
handlers and a level and it contains one handler. this is enough for
some simple logging to the console. the default logging level of the
-root logger is INFO. anything at level lower than INFO will not be
+root logger is <tt>INFO</tt> (20). anything at level lower than <tt>INFO</tt> will not be
logged.</p>
<code>
@@ -88,8 +98,8 @@
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>
+default console handler 'basic.stdout' to 30 (<tt>WARN</tt>). by
+the way, also handlers are environments.</p>
<code>
R> <user>addHandler(writeToConsole)</user><br/>
@@ -98,7 +108,8 @@
R> <user>logwarn('test')</user><br/>
2010-04-07 15:17:40 WARN::test <br/>
R> <user>with(getHandler('basic.stdout'), level)</user><br/>
-[1] 30<br/>
+WARN <br/>
+ 30 <br/>
R>
</code>
More information about the Logging-commits
mailing list