I am using a jar file in a java program and it generates warnings during runtime. But I don't want that my customer sees these warnings. How can I disable these warnings.
The warning is as below:
Sep 25, 2009 10:10:33 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'http://www.craigslist.org/js/jquery.js', but got 'application/x-javascript'.
A much easier way, without having to add Log4j as a dependency, is to simply redirect STDERR.
That's all you really need.
Note: Make sure you reset the stream after you are done with HtmlUnit:
From the appearance of the message, you are using HtmlUnit which uses Commons Logging for logging messages. Unless you configure Commons Logging to write to a file, the log messages will get logged by the simple logger of Commons Logging which writes out onto the console.
If you want to make the error messages go away you could adopt either of the options:
I found that HtmlUnit does not include the log4j implementation, only the commons logging "interface" (and abstract classes). Once you toss log4j.jar on the path, HtmlUnit behaves itself much better, and honors its configs.
Since the OP keeps asking how to redirect to /dev/null: You can achieve a similar effect by calling
System.setOut
andSystem.setErr
, passing in aPrintStream
that does nothing with the output it's given.This is a terrible hack, and the previous answers are far far cleaner.
Just copy first lines from the link Vineet posted:
Add this code somewhere in the beginning of the program.
Assuming these are log messages, you could configure the logger to write everything to null or /dev/null
Putting a file like this in the path might help