2

I'm using htmlunit [http://htmlunit.sourceforge.net/] and it spews out a bunch of warnings/error:

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]

I've looked at other resources and tried to turn it off by:

    Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
    Logger.getLogger("org.apache.http").setLevel(Level.OFF);

and:

        final WebClient webClient = new WebClient(BrowserVersion.EDGE);

but it does not work.

What else can be done to suppress these warning/error messages?

ikevin8me
  • 4,253
  • 5
  • 44
  • 84

2 Answers2

2

If you are not going set the loggers to OFF in 'logging.properties' file then you need pin the loggers with a hard reference before you set the level to OFF.

Here is a corrected example based off your code:

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);
    }
}
Community
  • 1
  • 1
jmehrens
  • 10,580
  • 1
  • 38
  • 47
-1

I put the following at the start of the application and the errors/warnings stopped:

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);
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
ikevin8me
  • 4,253
  • 5
  • 44
  • 84
  • You should [pin those loggers in memory](http://stackoverflow.com/questions/22689831/log-file-not-being-updated-after-few-seconds-while-using-logger-and-filehandler/22698423#22698423) before you set them to `OFF`. Otherwise you risk losing those settings you just applied. – jmehrens Mar 24 '17 at 12:58
  • I don't understand that. I don't need to keep those logs. – ikevin8me Mar 26 '17 at 06:13
  • If the loggers are not pinned by some code before you set them to `OFF` it is possible for loggers to be garbage collected. If that happens before htmlunit pins them, it is like you never set them to `OFF`. – jmehrens Mar 27 '17 at 13:55
  • Yeah, I saw them appearing again. It's annoying, like what you said. I don't understand the link you gave me either. What is the simplest way to keep those logs out? – ikevin8me Mar 28 '17 at 13:55