簡體   English   中英

如何隱藏htmlunit(Java庫)警告/錯誤消息?

[英]How to suppress htmlunit (Java library) warning/error messages?

我正在使用htmlunit [ http://htmlunit.sourceforge.net/] ,它會發出很多警告/錯誤:

2017年3月24日,下午6:37:30 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl通知警告:遇到過時的內容類型:“文本/ javascript”。 2017年3月24日,下午6:37:31 com.gargoylesoftware.htmlunit.html.InputElementFactory createElementNS INFO:錯誤的輸入類型:“ datetime”,創建了文本輸入。2017年3月24日,下午6:37:31 com.gargoylesoftware.htmlunit。 IncorrectnessListenerImpl通知警告:遇到過時的內容類型:'application / x-javascript'。 2017年3月24日,下午6:37:32 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl通知警告:遇到過時的內容類型:“應用程序/ x-javascript”。 2017年3月24日,下午6:37:34 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl通知警告:遇到過時的內容類型:“文本/ javascript”。 2017年3月24日,下午6:37:34 com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError嚴重:runtimeError:message = [指定了無效或非法的選擇器(選擇器:'* ,: x'錯誤:無效的選擇器::x )。] sourceName = [ https://www.example.com/bundles/jquery?v=u8J3xxyrazUhSJl-OWRJ6I82HpC6Fs7PQ0-l8XzoZXY1] line = [1] lineSource = [null] lineOffset = [0] 2017年3月24日6:37 :下午35點com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl通知警告:遇到過時的內容類型:“文本/ javascript”。 2017年3月24日,下午6:37:35 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl通知警告:遇到過時的內容類型:“文本/ javascript”。 2017年3月24日,下午6:37:35 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl通知警告:遇到過時的內容類型:“文本/ javascript”。 2017年3月24日,下午6:37:36 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl通知警告:遇到過時的內容類型:“文本/ javascript”。 2017年3月24日,下午6:37:43 com.gargoylesoftware.htmlunit.javascript.host.dom.Document createElement信息:createElement:提供了字符串'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 ,則在將級別設置為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);
    }
}

我在應用程序的開頭放置了以下內容,並且錯誤/警告停止了:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM