Hi Brian,
In general, R lacks many utilities for "applications". I'd say
it's more focused on "one-shot" analysis, what is logic given its
origin in statistics/academics. Few packages deal with these types
of "application automation".
Logging is already addressed in some packages: you should have
a look at "Verbose" on R.utils. "logger" on Rcmdr has a
different
purpose (logging commands, not messages), but you should consider
the name clash with your functions, as well as potential problems
with S3 dispatching.
Logging is one of these types of utilities where one good
package could be useful to many of us. Here are some personal
ideas about what would make a general R logging tool useful:
1) It should be on a package of its own. Embedding it into a
general "tools & utilities" package like "futile" only
dilutes
it. It becomes much harder to find, and forces the interested user
to load a lot of unrelated stuff which is likely not useful to him.
2) It should, if possible, be built on top of the condition
handling system of R.
3) It should build on the message translation system of R
(the set of "gettext", "gettextf", etc, functions)
4) It should be R-like, not Java-like. I don't think mimicking
a Java system like log4j is specially useful, and having that as
the main design statement can only be --in my very personal
opinion-- harmful, unless you're really interfacing to Java code.
You may get some inspiration from it but R and Java are
different enough that forcing too much in that direction is
unlikely to lead to a great R package.
Hope this is useful. Regards,
Enrique
------------------------------
Date: Mon, 20 Jul 2009 07:55:53 -0400
From: B Rowe <public_browe at muxspace.com>
Subject: [R] Application logging in R
To: r-help at r-project.org
Message-ID: <1248090953.4586.52.camel at localhost>
Content-Type: text/plain
Hello,
I'm curious to know how people log their applications in R. It seems
like it's a combination of cat statements or writing out the session to
a file, given the discussions I've had with people. This is fine for
interactive work but is a little lacking for automated systems. To
address this, I've written a logging facility modeled on the log4j Java
library. The basic concept is that you can route logging statements to
customizable loggers, each with their own 'threshold' (e.g. debug, info,
warn) and output. The output can be anything from stdout, a file, a URL,
to a message bus, depending on the implementation.
Here are some quick examples:
library(futile)
# Use the ROOT logger
logger.info("Hello, world")
logger.debug("Won't print since level is currently INFO")
setLogger('ROOT', level='DEBUG')
logger.debug("This will %s print", 'now')
# Create new loggers
addLogger('a.logger', 'WARN', logger.stdout)
addLogger('b.logger', 'INFO', logger.file,
file='temp.log')
object <- 1
logger.debug("This is a %s", class(object),
logger='a.logger')
logger.warn("This is a %s", class(object),
logger='b.logger')
This type of control also provides an alternative to stdout redirection
in distributed environments, which can facilitate debugging.
Version 1.1.1 of the package is available on CRAN. Any thoughts on how
to improve this or requests for other loggers are appreciated.
Regards,
Brian