关闭HtmlUnit警告

您知道如何关闭HtmlUnit中的警告,注释和错误吗?



杨魅力
浏览 1001回答 3
3回答

忽然笑

将其放在代码开始处;它会闭上它的脏嘴:LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF); java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF);webClient = new WebClient(bv);webClient.setCssEnabled(false);webClient.setIncorrectnessListener(new IncorrectnessListener() {    @Override    public void notify(String arg0, Object arg1) {        // TODO Auto-generated method stub    }});webClient.setCssErrorHandler(new ErrorHandler() {    @Override    public void warning(CSSParseException exception) throws CSSException {        // TODO Auto-generated method stub    }    @Override    public void fatalError(CSSParseException exception) throws CSSException {        // TODO Auto-generated method stub    }    @Override    public void error(CSSParseException exception) throws CSSException {        // TODO Auto-generated method stub    }});webClient.setJavaScriptErrorListener(new JavaScriptErrorListener() {    @Override    public void timeoutError(HtmlPage arg0, long arg1, long arg2) {        // TODO Auto-generated method stub    }    @Override    public void scriptException(HtmlPage arg0, ScriptException arg1) {        // TODO Auto-generated method stub    }    @Override    public void malformedScriptURL(HtmlPage arg0, String arg1, MalformedURLException arg2) {        // TODO Auto-generated method stub    }    @Override    public void loadScriptError(HtmlPage arg0, URL arg1, Exception arg2) {        // TODO Auto-generated method stub    }});webClient.setHTMLParserListener(new HTMLParserListener() {    @Override    public void warning(String arg0, URL arg1, int arg2, int arg3, String arg4) {        // TODO Auto-generated method stub    }    @Override    public void error(String arg0, URL arg1, int arg2, int arg3, String arg4) {        // TODO Auto-generated method stub    }});webClient.setThrowExceptionOnFailingStatusCode(false);webClient.setThrowExceptionOnScriptError(false);

莫回无

Arsen Zahray的答案中的代码有助于删除HtmlUnit生成的几乎所有日志。但是进行一次编辑有助于将其全部删除。使用:java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); 代替:java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
打开App,查看更多内容
随时随地看视频慕课网APP