2017-03-24 28 views
1

我使用的HtmlUnit [http://htmlunit.sourceforge.net/],它喷出了一堆警告/错误:如何禁止htmlunit(Java库)警告/错误消息?

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); 

不起作用

还能做些什么来抑制这些警告/错误信息?

+0

确保调用之前的HtmlUnit要设置记录器。如果没有,请发布您的完整代码 –

+0

谢谢,我把代码和多一行(请参阅我的答案),错误/收入停止出现。 – ikevin8me

回答

3

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

这是基于把你的代码校正例如:

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); 
    } 
} 
+0

谢谢!现在我明白你的意思是“固定”在记忆中。 :-) – ikevin8me

0

我把在应用程序和错误的开始,以下/警告停止:

System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "fatal"); 
Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF); 
Logger.getLogger("org.apache.http").setLevel(Level.OFF); 
+0

你应该[将这些记录器固定在内存中](http://stackoverflow.com/questions/22689831/log-file-not-being-updated-after-few-seconds-while-using-logger-and-filehandler/22698423 #22698423),然后将它们设置为“OFF”。否则,您可能会失去刚刚应用的设置。 – jmehrens

+0

我不明白。我不需要保留这些日志。 – ikevin8me

+0

如果记录器在被设置为“OFF”之前未被某些代码固定,则记录器可能被垃圾收集。如果在htmlunit发布之前发生这种情况,就好像你从未将它们设置为“关闭”。 – jmehrens