Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you are using Java Logging API and if you have a java class like the next:</p> <pre><code>import java.util.logging.Level; import static java.util.logging.Level.*; import java.util.logging.Logger; public class Main { private static final Logger LOG = Logger.getLogger(Main.class.getName()); public static void main(String[] args) { Level[] levels = { OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL }; for (Level level : levels) { LOG.setLevel(level); LOG.log(level, "Hello Logger"); } } } </code></pre> <p>You notice that the output is:</p> <pre><code>Jun 7, 2013 6:30:16 PM Main main SEVERE: Hello Logger Jun 7, 2013 6:30:16 PM Main main WARNING: Hello Logger Jun 7, 2013 6:30:16 PM Main main INFO: Hello Logger </code></pre> <p>What happens? What about the other levels? What am I doing wrong? Don't worry. Be happy! This is because the default level for Java Logging API is <code>INFO</code>. You can find this in the configuration file <code>logging.properties</code> in the JRE, e.g. </p> <pre><code>D:\Software\jdk1.6.0_43\jre\lib\logging.properties </code></pre> <p>In this file, we can see the lines:</p> <pre><code># Default global logging level. # This specifies which kinds of events are logged across # all loggers. For any given facility this global level # can be overriden by a facility specific level # Note that the ConsoleHandler also has a separate level # setting to limit messages printed to the console. .level= INFO </code></pre> <p>And, as the text indicates, the level for the console handler:</p> <pre><code># Limit the message that are printed on the console to INFO and above. java.util.logging.ConsoleHandler.level = INFO </code></pre> <p>This is the reason why the maximum level of detail in the output is <code>INFO</code>. You can change the level in this file or in your code (this is best to not affect the level of other processes), e.g.:</p> <pre><code>import java.util.logging.ConsoleHandler; import java.util.logging.Handler; import java.util.logging.Level; import static java.util.logging.Level.*; import java.util.logging.Logger; public class Main { private static final Logger LOG = Logger.getLogger(Main.class.getName()); public static void main(String[] args) { Level[] levels = { OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL }; Logger root = Logger.getLogger(""); // .level= ALL root.setLevel(ALL); for (Handler handler : root.getHandlers()) { if (handler instanceof ConsoleHandler) { // java.util.logging.ConsoleHandler.level = ALL handler.setLevel(ALL); } } for (Level level : levels) { LOG.setLevel(level); LOG.log(level, "Hello Logger"); } } } </code></pre> <p>The output for the last code is:</p> <pre><code>Jun 7, 2013 6:31:13 PM Main main SEVERE: Hello Logger Jun 7, 2013 6:31:13 PM Main main WARNING: Hello Logger Jun 7, 2013 6:31:13 PM Main main INFO: Hello Logger Jun 7, 2013 6:31:13 PM Main main CONFIG: Hello Logger Jun 7, 2013 6:31:13 PM Main main FINE: Hello Logger Jun 7, 2013 6:31:13 PM Main main FINER: Hello Logger Jun 7, 2013 6:31:13 PM Main main FINEST: Hello Logger Jun 7, 2013 6:31:13 PM Main main ALL: Hello Logger </code></pre> <p><strong>EDIT</strong></p> <p>You can also use another file <code>logging.properties</code> whith the desired level adding an argument to the virtual machine:</p> <pre><code>-Djava.util.logging.config.file="C:\mylogging.properties" </code></pre>
 

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