I am using java.util.logging.Logger and I want to restrict the log level to SEVERE, but he does not respect that and logs everything. What is 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");
}
Both the message 1 ("Teste1") and message 2 ("Test2") are being logged. How do I restrict the log level to SEVERE for only the second message ("Test2) appears?