I use java.util.logging.Logger and I want to limit the level of the SEVERE log, but it does not respect this and writes everything. What's wrong?
private static final Logger log = Logger.getLogger(MyClass.class.getName()); private Handler fileHandler = null; public static void myMethod(){ fileHandler = new FileHandler("file", 1000000, 1, true); log.setLevel(Level.SEVERE); fileHandler.setLevel(Level.SEVERE); SimpleFormatter formatter = new SimpleFormatter(); fileHandler.setFormatter(formatter); log.addHandler(fileHandler); log.log(Level.INFO, "Test1"); log.log(Level.SEVERE, "Test2"); }
Message 1 ("Teste1") and message 2 ("Test2") are recorded. How to limit the level of the SEVERE log to only the second message ("Test2")?
David source share