无法关闭HtmlUnit日志记录消息

编程入门 行业动态 更新时间:2024-10-25 19:23:19
本文介绍了无法关闭HtmlUnit日志记录消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用HtmlUnit与通过Ajax与服务器交互的网页进行交互. Ajax代码启动后不久,HtmlUnit会生成以下两条日志消息:

I'm using HtmlUnit to interact with a web page that interacts with the server via Ajax. Soon after the Ajax code starts, HtmlUnit produces these two log messages:

WARNING: Ignoring XMLHttpRequest.setRequestHeader for Content-length: it is a restricted header Mar 3, 2011 3:32:47 PM com.gargoylesoftware.htmlunit.javascript.host.xml.XMLHttpRequest jsxFunction_setRequestHeader WARNING: Ignoring XMLHttpRequest.setRequestHeader for Connection: it is a restricted header Mar 3, 2011 3:32:47 PM com.gargoylesoftware.htmlunit.javascript.host.xml.XMLHttpRequest jsxGet_status

...此消息之后,重复了六次:

...Followed by this message, repeated six times:

SEVERE: XMLHttpRequest.status was retrieved before the response was available. Mar 3, 2011 3:32:47 PM com.gargoylesoftware.htmlunit.javascript.host.xml.XMLHttpRequest jsxGet_status

我不知道如何关闭这些消息.遍历代码表明,它们是由直接调用记录器而不是通过处理程序对象产生的,而我可以为CSS错误做这件事,而该处理程序对象我可以为此提供不做任何事情的实现. HtmlUnit日志记录页面指示添加以下代码应该可以:

I can't figure out how to turn these messages off. Trawling through the code shows that they're produced by direct calls to a logger, not via a handler object that I could provide a do-nothing implementation for, as I already do for CSS errors. The HtmlUnit logging page indicates that adding this code should work:

System.getProperties().put("org.apachemons.logging.simplelog.defaultlog", "fatal");

...但是没有效果.我还尝试在调用Java的地方添加以下选项:

...but it has no effect. I also tried adding the following option where I invoke java:

-Dorg.apachemons.logging.simplelog.defaultlog=fatal

...但这也没有效果.

...but that also has no effect.

我想我可以在执行此代码的同时将stderr重定向到/dev/null,但是还可以使用其他一些较黑的解决方案吗?

I guess I could redirect stderr to /dev/null while this code is executing, but are any less hacky solutions available?

推荐答案

我对此也有疑问. 答案取决于引擎盖下使用的是哪种日志记录系统commons-logging. (因为common-logging只是一个包装器).见以下 commons.apache/proper/commons-logging/guide.html#Configuring_The_Underlying_Logging_System

I too had issues with this.. The answer depends on what logging system commons-logging is using under the hood. (since common-logging is just a wrapper). See the following commons.apache/proper/commons-logging/guide.html#Configuring_The_Underlying_Logging_System

您上面提到的属性(org.apachemons.logging.simplelog.defaultlog)仅在使用简单记录器的情况下才有效.如果您在JDK 1.4或更高版本上运行,则应默认使用JDK日志记录.在这种情况下,默认情况下是从JRE安装位置使用lib/logging.properties.

The attribute you mention above (org.apachemons.logging.simplelog.defaultlog) should only be valid if the simple logger is been used. If you are running on JDK 1.4 or higher however it should default to using the JDK logging. In which case it defaults to using the lib/logging.properties from the JRE install location.

在我的情况下,我在类路径中有Log4j,所以它默认为Log4j.

In my case I had Log4j in the classpath, so it defaulted to that.

要消除所有这些随机性,您可以自己明确设置Logger.在类路径中创建commons-logging.properties文件,并通过记录器以使用例如

To take away the randomness of all this you can explicitly set the Logger yourself. Create a commons-logging.properties file in the classpath and pass in the logger to use e.g.

# JDK Logging #org.apachemons.logging.Log=org.apachemons.logging.impl.Jdk14Logger # Log4j logging (also required log4j.jar to be in classpath) org.apachemons.logging.Log=org.apachemons.logging.impl.Log4JLogger

对于log4j,添加以下log4j.properties可停止来自HtmlUnit的警告.

For log4j, adding the following the log4j.properties stops the warnings from HtmlUnit.

log4j.logger.gargoylesoftware.htmlunit=ERROR

更多推荐

无法关闭HtmlUnit日志记录消息

本文发布于:2023-11-25 04:15:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628280.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:消息   日志   HtmlUnit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!