我正在使用 java.util.logging.Logger 并且我想将日志级别限制为 SEVERE,但他不尊重这一点并记录所有内容。怎么了?
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");
}
正在记录消息 1(“Teste1”)和消息 2(“Test2”)。如何将日志级别限制为 SEVERE,仅出现第二条消息(“Test2)?