Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting java.util.logging.config.file at runtime
    primarykey
    data
    text
    <p>I am trying to set the java util logging config file at runtime to avoid having to set it as a VM parameter. But this just doesn't work. Whenever I am trying to reread the configuration, logging is disabled at all.</p> <p>See the following code snippet:</p> <pre class="lang-java prettyprint-override"><code>package test; import java.io.FileInputStream; import java.util.logging.Level; import java.util.logging.LogManager; import java.util.logging.Logger; public class A { private static final Logger LOGGER= Logger.getLogger(A.class.getName()); public static void main(String[] args) throws Exception { System.out.println("--- start"); LOGGER.log(Level.SEVERE, "SEVERE 1"); LOGGER.log(Level.FINEST, "FINEST 1"); LogManager.getLogManager().readConfiguration(); LOGGER.log(Level.SEVERE, "SEVERE 2"); LOGGER.log(Level.FINEST, "FINEST 2"); LogManager.getLogManager().readConfiguration(new FileInputStream("/tmp/logging.properties")); LOGGER.log(Level.SEVERE, "SEVERE 3"); LOGGER.log(Level.FINEST, "FINEST 3"); System.out.println("--- end"); } } </code></pre> <p>This is the output if I run the class without any VM argument: </p> <pre><code>--- start 09.11.2012 09:59:25 test.A main SCHWERWIEGEND: SEVERE 1 09.11.2012 09:59:25 test.A main SCHWERWIEGEND: SEVERE 2 --- end </code></pre> <p>As you can see, only the SEVERE levels are logged, as this is the default of the JREs logging.properties. Calling <code>LogManager#readConfiguration()</code> doesn't change anything. But when trying to read the configuration from my logging.properties, absolutely nothing is logged. There is no difference in calling <code>LogManager#readConfiguration(InputStream)</code> or setting the <code>java.util.logging.config.file</code> property and calling <code>LogManager#readConfiguration()</code>.</p> <p>Now see the next output, when I run the same code with the VM property <code>-Djava.util.logging.config.file=/tmp/logging.properties</code> : </p> <pre><code>--- start 2012-11-09 10:03:44.0838 SEVERE [test.A#main()] - SEVERE 1 2012-11-09 10:03:44.0843 FINEST [test.A#main()] - FINEST 1 --- end </code></pre> <p>As you can see, both the SEVERE and the FINEST levels are logged and they are logged in a different format. Both is specified in my custom <code>logging.properties</code>. But logging stops here after calling <code>LogManager#readConfiguration()</code>! This is different from the example above and I don't understand it. Also, just as in the example above, calling <code>LogManager#readConfiguration(InputStream)</code> doesn't work.</p> <p>So what is the problem? According to the <a href="http://docs.oracle.com/javase/6/docs/api/java/util/logging/LogManager.html" rel="noreferrer">javadoc</a> setting the java.util.logging.config.file property at runtime should work. Also both readConfiguration() methods should work as I expect. So what is the problem?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload