Use the java.util.logging.config.file system property and point it to the NUL device.
On Windows:
-Djava.util.logging.config.file=NUL
On Linux:
-Djava.util.logging.config.file=/dev/null
On any platform you can simply create an empty file and point to it.
What this does is on startup the LogManager.readConfiguration() is called with the given file path (stream). Per the contract this method will:
Reinitialize the logging properties and reread the logging configuration
When it reads the logging configuration there is no new data to read. Therefore, this behaves as if it was just calling LogManager.reset() on startup.
If you want more selective behavior on the root logger then you write a custom class and use the java.util.logging.config.class
property:
package foo.bar;
import java.io.FileInputStream;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.LogManager;
import java.util.logging.Logger;
public final class LogConfig {
public LogConfig() throws Throwable {
//Load the default config file.
String file = System.getProperty("java.util.logging.config.file");
if (file != null) {
LogManager.getLogManager().readConfiguration(new FileInputStream(file));
}
//Modify the logger tree if property is set.
String key = "some.config.property";
String v = System.getProperty(key);
if (v == null) {
throw new NullPointerException("System property '"
+ key + "' was not defined");
}
if (Boolean.parseBoolean(v)) {
Logger root = Logger.getLogger("");
for (Handler h : root.getHandlers()) {
if (h instanceof FileHandler) {
root.removeHandler(h);
h.close();
}
}
}
}
}
The to use this class you set the following command line properties:
-Djava.util.logging.config.file=/path/to/file -Djava.util.logging.config.class=foo.bar.LogConfig -Dsome.config.property=true