Desactivar las advertencias de HtmlUnit


¿Sabes cómo puedo desactivar Advertencias, Notas y Errores en HtmlUnit?

Author: oneat, 2010-08-30

13 answers

Pon esto en algún lugar alrededor del comienzo de tu código, cerrará su sucia boca:

    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);
 94
Author: Arsen Zahray,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-26 06:33:53

Arsen.. muchas gracias por la respuesta .. El uso de su código ayudó a eliminar casi todos los registros de HtmlUnit. Pero una edición ayuda a eliminarlos todos:

Uso:

java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); 

En lugar de

java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF); 
 41
Author: sha,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-07-26 17:48:08

Para eliminar toda la salida de la última versión de HtmlUnit solo tienes que añadir estas líneas en un bloque estático o en tu clase principal:

java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); 
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");

NO es necesario sobrescribir ningún método como dicen otras respuestas.

 30
Author: Mosty Mostacho,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-09-01 22:29:45

Aquí puede obtener información sobre cómo manipular el registro de HtmlUnit.

Esto es lo que agregué a mi log4j. properties para deshabilitar los mensajes de depuración detallados de los componentes HtmlUnit:

# Set specific logger levels.
log4j.logger.org.mortbay.log=fatal
log4j.logger.org.apache.http=fatal
log4j.logger.org.apache.http.headers=fatal
log4j.logger.org.apache.http.wire=fatal
# For HttpClient 3, which is used by FirefoxDriver
log4j.logger.httpclient.wire=fatal
log4j.logger.org.apache.commons=fatal
log4j.logger.com.gargoylesoftware.htmlunit=fatal
log4j.logger.com.gargoylesoftware.htmlunit.WebTestCase=fatal
# Change this to TRACE when enabling the debugger.
log4j.logger.com.gargoylesoftware.htmlunit.javascript.DebugFrameImpl=fatal
 12
Author: Ivanov Artemk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-10-28 17:37:32

Prueba esto:

  java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
 12
Author: some_other_guy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-15 11:47:51

Estoy usando el siguiente código y prefecto de ti.

 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);
 6
Author: Adnan Ghaffar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-02-12 18:53:20

Simplemente agregue a su log4.propiedades de esta cadena log4j.logger.com.gargoylesoftware.htmlunit=fatal

 3
Author: mike,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-21 21:50:16

Echa un vistazo a los documentos .

Hay un archivo log4 de ejemplo utilizado por el conjunto de pruebas, puede encontrarlo aquí, puede desactivar todo si lo desea.

 2
Author: Ahmed Ashour,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-08-31 02:04:17

Esto funcionó para mí

@Test
    public void homePage() throws Exception {
        final WebClient webClient = new WebClient();   
 webClient.setThrowExceptionOnScriptError(false);
    final HtmlPage page = webClient.getPage("http://localhost:8080/web/guest/home");
 2
Author: Alex Punnen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-06 11:28:03

Apague los registradores. Pero esa no es una buena solución, ya que es posible que desee tener algunos problemas poco comunes en los registros.

Conozco Htmlunit, produce muchas excepciones sin importancia, advertencias, etc.

Puede suprimir algunos de los que utilizan:

client.getOptions().setThrowExceptionOnFailingStatusCode(false);
client.getOptions().setThrowExceptionOnScriptError(false);
client.getOptions().setPrintContentOnFailingStatusCode(false);
 2
Author: coding_idiot,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-03 13:32:31

Ahora en htmlunit 2.9,WebClient.setCssErrorHandler (new SilentCssErrorHandler ()) puede ignora convenientemente las advertencias y errores.

@Override
protected WebClient modifyWebClient(WebClient client) {
    // currently does nothing, but may be changed in future versions
    WebClient modifiedClient = super.modifyWebClient(client);

    modifiedClient.getOptions().setThrowExceptionOnScriptError(false);
    modifiedClient.setCssErrorHandler(new SilentCssErrorHandler());

    return modifiedClient;
}
 1
Author: Howard,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-22 03:57:41

Intenta agregar esto a tu código :

LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");

Básicamente, logger registra en NoOpLog que no escribe log en error o archivo o en cualquier lugar.

 1
Author: Salman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-25 01:19:57

Una opción que funcionó bien para mí es cambiar el logger de htmlunit para iniciar sesión en un archivo diferente solo para que tenga esos errores en caso de que necesite referirlo algún tiempo y también no desordene mis registros principales. A continuación se muestra el cambio log4j que hice en log4j. properties:

log4j.logger.com.gargoylesoftware.htmlunit=ERROR, HTMLUNIT
log4j.additivity.com.gargoylesoftware.htmlunit=false
log4j.appender.HTMLUNIT = org.apache.log4j.RollingFileAppender
log4j.appender.HTMLUNIT.layout=org.apache.log4j.PatternLayout
log4j.appender.HTMLUNIT.layout.ConversionPattern=%m%n
log4j.appender.HTMLUNIT.File=logs/HtmlUnitLog4j.log
log4j.appender.HTMLUNIT.MaxFileSize=5MB
log4j.appender.HTMLUNIT.MaxBackupIndex=5
 0
Author: vanval,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-14 22:40:58