當記錄到MemoryHandler時,MemoryHandler在numofentries> size時刪除較舊的條目。避免丟棄MemoryHandler中的舊條目
我想避免這種行爲,或者至少將日誌記下來,舊的條目被抑制。
小測試案例:
import java.util.logging.*;
public class SSCE01 {
public static void main (String [] args) {
Logger rootLogger = Logger.getLogger("");
rootLogger.removeHandler(rootLogger.getHandlers()[0]); //remove default Console Handler
ConsoleHandler ch = new ConsoleHandler();
Logger l = Logger.getLogger("test");
MemoryHandler mh = new MemoryHandler(ch,3,Level.OFF);
l.addHandler(mh);
l.severe("this shouldnt be logged");
l.severe("this shouldnt be logged");
l.severe("this shouldnt be logged");
l.severe("this should be logged");
l.severe("this should be logged");
l.severe("this should be logged");
mh.push();
}
}
看到新版本的答案我認爲它現在更接近你所需要的。我希望它有幫助。 – 2011-05-23 10:17:46