开发者

R: getting chatty Java processes to STFU

I'm using rJava to speak to the Amazon Web Services Java API from insi开发者_开发问答de of R. After some initial pain I have it working. But the API is VERY chatty and feedbacks to R a huge amount of info that is great for debugging, but now that my code works, I'd like to silence this info chatter. How would I go about getting rid of this chatter? I'm not even sure where to look. The API? rJava? A switch in R?

Any help in where to look would be appreciated. Here's an example of the info chatter:

R> result <- uploadS3File(clusterObject$s3TempDir, streamFile)
Dec 17, 2010 12:12:52 PM com.amazonaws.http.HttpClient execute
INFO: Sending Request: PUT https://rtmphgdfkoughcboh8kl.s3.amazonaws.com /stream.txt Headers: (Authorization: AWS AKIAIC2FRTLFVNIOTMAQ:E++Z54SQsgoAntZ7JAd6aWJ2ZVs=, Date: Fri, 17 Dec 2010 18:12:52 GMT, Content-Length: 255579, Content-MD5: pMFNOWPJswXpAEULjfOclw==, Content-Type: text/plain, ) 
Dec 17, 2010 12:12:53 PM com.amazonaws.http.HttpClient handleResponse
INFO: Received successful response: 200, AWS Request ID: FC4113F003FCF631
R> 


Jeffrey Breen's answer pointed me in the right direction. I did some digging around on log4j and discovered, thanks to the AWS forum, that the Java AWS API does not come with log4j set up, but it's really really easy to add. All I had to do was add the file log4j-1.2.16.jar to my class path. Then I created a log4J.properties file using the examples in the API docs. Then I added the directory where I put my log4j.properties file to my classpath and it worked!

so my the first bit of my .onLoad() function looks like this:

.onLoad <- function(lib, pkg) {
    pathToSdk <- paste(system.file(package = "segue") , "/aws-java-sdk/", sep="")

    jarPaths <- c(paste(pathToSdk, "lib/aws-java-sdk-1.1.0.jar", sep=""),
                  paste(pathToSdk, "third-party/commons-logging-1.1.1/commons-logging-1.1.1.jar", sep=""),
                  paste(pathToSdk, "third-party/commons-httpclient-3.0.1/commons-httpclient-3.0.1.jar", sep=""),
                  paste(pathToSdk, "third-party/commons-codec-1.3/commons-codec-1.3.jar", sep=""),
                  paste(pathToSdk, "third-party/log4j-1.2.16.jar", sep=""),
                  paste(pathToSdk, "third-party/", sep="")
                  )
    .jpackage(pkg, morePaths=jarPaths)

  ## other stuff edited out

 }

and my log4j.properties file has this in it:

log4j.rootLogger=WARN, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c -  %m%n

and my log4j.properties file is located in the third-party/ directory which you can see is in the classpath.


I agree with Romain: they look like standard log4j messages to me.

Loggers may be assigned levels. http://logging.apache.org/log4j/1.2/manual.html lists the possible logging levels: TRACE, DEBUG, INFO, WARN, ERROR and FATAL.

It looks like you're running at least at INFO and you probably want ERROR or FATAL.

My first guess would be to look around for a "log4j.properties" file, probably part of rJava as that's what calling the Java code, right? If it's stuck in a JAR file, you may want to extract, modify, and point to with a flag on rJava's java invocation, like "-Dlog4j.configuration=/path/to/log4j.properties"

Added:

Looking at the rJava docs now... are you calling .jinit() yourself? That's the function which invokes the JVM. If so, it takes a silent parameter which is worth a shot. Or, do above and add the flag to the parameters vector.


It depends on how the chatter is being generated. I'd start by trying:

suppressMessages({
  result <- uploadS3File(clusterObject$s3TempDir, streamFile)
  # other chatter-generating code
})


This looks like typical java logging . I'd guess java does all the talking and so you probably should look into a solution in the java api. Or maybe you can sink into /dev/null

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜