R:将繁琐的 Java 进程引入 STFU

发布于 2024-10-08 07:34:55 字数 835 浏览 6 评论 0原文

我正在使用 rJava 从 R 内部与 Amazon Web Services Java API 进行通信。在经历了一些最初的痛苦之后,我让它可以工作了。但是 API 非常喋喋不休,并向 R 反馈了大量非常有利于调试的信息,但现在我的代码可以工作了,我想消除这些信息的喋喋不休。我该如何摆脱这种喋喋不休的情况呢?我什至不知道该去哪里寻找。 API? Java? R 中的开关?

任何关于在哪里查看的帮助将不胜感激。这是信息聊天的示例:

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> 

I'm using rJava to speak to the Amazon Web Services Java API from inside 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> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

四叶草在未来唯美盛开 2024-10-15 07:34:55

Jeffrey Breen的回答为我指明了正确的方向。我在 log4j 上做了一些挖掘,发现感谢 AWS 论坛,Java AWS API 并未附带 log4j 设置,但添加它确实非常容易。我所要做的就是将文件 log4j-1.2.16.jar 添加到我的类路径中。然后我使用 API 文档中的示例创建了一个 log4J.properties 文件< /a>.然后我添加了将 log4j.properties 文件放置到类路径中的目录,并且它起作用了!

所以我的 .onLoad() 函数的第一部分看起来像这样:

.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

 }

我的 log4j.properties 文件中有这个:

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

我的 log4j.properties 文件位于第三方/目录中,您可以看到它位于类路径中。

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.

秉烛思 2024-10-15 07:34:55

我同意 Romain 的观点:对我来说它们看起来就像标准的 log4j 消息。

记录器可以被分配级别。 http://logging.apache.org/log4j/1.2/manual.html列出可能的日志记录级别:TRACE、DEBUG、INFO、WARN、ERROR 和 FATAL。

看起来您至少在​​ INFO 处运行,并且您可能需要 ERROR 或 FATAL。

我的第一个猜测是寻找“log4j.properties”文件,可能是 rJava 的一部分,因为这就是调用 Java 代码的原因,对吗?如果它卡在 JAR 文件中,您可能需要提取、修改并使用 rJava 的 java 调用上的标志指向,例如“-Dlog4j.configuration=/path/to/log4j.properties”

添加:

查看 rJava 文档现在...您自己调用 .jinit() 吗?这是调用 JVM 的函数。如果是这样,它需要一个值得一试的silent参数。或者,执行上述操作并将标志添加到 parameters 向量中。

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.

冧九 2024-10-15 07:34:55

这取决于喋喋不休的产生方式。我首先尝试:

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

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

suppressMessages({
  result <- uploadS3File(clusterObject$s3TempDir, streamFile)
  # other chatter-generating code
})
喜爱纠缠 2024-10-15 07:34:55

这看起来像典型的 java 日志记录。我猜想 java 会解决所有问题,所以你可能应该在 java api 中寻找解决方案。或者也许你可以陷入 /dev/null

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文