tags:

views:

172

answers:

2

I'd like to know how to programatically turn off java logging - no property files, no command line arguments etc.

I've tried:

final Properties logProperties = new Properties();
logProperties.put("handlers", "java.util.logging.MemoryHandler");
logProperties.put(".level", "SEVERE");
logProperties.put("java.util.logging.ConsoleHandler.level", "SEVERE");

final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
logProperties.store(bytes, applicationName);
new String(bytes.toByteArray());
LogManager.getLogManager().readConfiguration(new ByteArrayInputStream(bytes.toByteArray()));

but the third party library (Flying Saucer) continues to log all its messages regardless of what I do.

It doesn't matter so much in production, but it is really annoying in my IDE to get these console messages all over the show. (At a future point, I shall redirect to another logging framework...)

+3  A: 
System.setProperty("show-config", "OFF");
System.setProperty("xr.util-logging.plumbing.layout.level", "OFF");
System.setProperty("xr.util-logging.plumbing.config.level", "OFF");
System.setProperty("xr.util-logging.plumbing.load.xml-entities.level",
      "OFF");
System.setProperty("xr.util-logging.plumbing.init.level", "OFF");
System.setProperty(
        "xr.util-logging.java.util.logging.ConsoleHandler.level", "OFF");
System.setProperty("xr.util-logging.plumbing.exception.level", "OFF");
System.setProperty("xr.util-logging.plumbing.match.level", "OFF");
System.setProperty("xr.util-logging..level", "OFF");
System.setProperty("xr.util-logging.plumbing.cascade.level", "OFF");
System.setProperty("xr.util-logging.plumbing.load.level", "OFF");
System.setProperty("xr.util-logging.plumbing.css-parse.level", "OFF");
System.setProperty("xr.util-logging.plumbing.render.level", "OFF");
System.setProperty("xr.util-logging.plumbing.level", "OFF");
System.setProperty("xr.util-logging.plumbing.general.level", "OFF");

(per https://xhtmlrenderer.dev.java.net/servlets/ReadMsg?list=users&msgNo=142)

Yuval A
A: 

Similar to Yuval's answer:

System.setProperty("xr.util-logging.loggingEnabled", "false")

This works for xr(enderer), but I'm really on the lookout for the magic one to turn off all logging (although this is nice for me now...)

Stephen