2017-03-24 48 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