gpt4 book ai didi

java - 如何抑制 htmlunit(Java 库)警告/错误消息?

转载 作者:行者123 更新时间:2023-11-30 02:36:15 26 4
gpt4 key购买 nike

我正在使用 htmlunit [http://htmlunit.sourceforge.net/]它会发出一堆警告/错误:

Mar 24, 2017 6:37:30 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Obsolete content type encountered: 'text/javascript'. Mar 24, 2017 6:37:31 PM com.gargoylesoftware.htmlunit.html.InputElementFactory createElementNS INFO: Bad input type: "datetime", creating a text input Mar 24, 2017 6:37:31 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Obsolete content type encountered: 'application/x-javascript'. Mar 24, 2017 6:37:32 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Obsolete content type encountered: 'application/x-javascript'. Mar 24, 2017 6:37:34 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Obsolete content type encountered: 'text/javascript'. Mar 24, 2017 6:37:34 PM com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError SEVERE: runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' error: Invalid selector: :x).] sourceName=[https://www.example.com/bundles/jquery?v=u8J3xxyrazUhSJl-OWRJ6I82HpC6Fs7PQ0-l8XzoZXY1] line=[1] lineSource=[null] lineOffset=[0] Mar 24, 2017 6:37:35 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Obsolete content type encountered: 'text/javascript'. Mar 24, 2017 6:37:35 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Obsolete content type encountered: 'text/javascript'. Mar 24, 2017 6:37:35 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Obsolete content type encountered: 'text/javascript'. Mar 24, 2017 6:37:36 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Obsolete content type encountered: 'text/javascript'. Mar 24, 2017 6:37:43 PM com.gargoylesoftware.htmlunit.javascript.host.dom.Document createElement INFO: createElement: Provided string 'iframe name="rufous-frame-29_-1">https://platform.twitter.com/widgets.js] line=[9] lineSource=[null] lineOffset=[0]

我查看了其他资源并尝试通过以下方式将其关闭:

    Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
Logger.getLogger("org.apache.http").setLevel(Level.OFF);

和:

        final WebClient webClient = new WebClient(BrowserVersion.EDGE);

但是它不起作用

还可以采取什么措施来抑制这些警告/错误消息?

最佳答案

如果您不打算在“logging.properties”文件中将记录器设置为OFF,那么您需要pin the loggers with a hard reference在将级别设置为“关闭”之前。

这是一个基于您的代码的更正示例:

private static final Logger[] PINNED_LOGGERS;
static {
System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "fatal");
PINNED_LOGGERS = new Logger[]{
Logger.getLogger("com.gargoylesoftware.htmlunit"),
Logger.getLogger("org.apache.http")
};

for (Logger l : PINNED_LOGGERS) {
l.setLevel(Level.OFF);
}
}

关于java - 如何抑制 htmlunit(Java 库)警告/错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42996056/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com