今天將寫好的代碼放到ubuntu上測試,發現了幾個問題。
1:每次svn update源碼,tomcat重新部署以後 log 檔案會消失~~
查看源碼發現:
java.util.logging.FileHandlerprivate void configure() { LogManager manager = LogManager.getLogManager();String cname = getClass().getName();pattern = manager.getStringProperty(cname + ".pattern", "%h/java%u.log");limit = manager.getIntProperty(cname + ".limit", 0);if (limit < 0) { limit = 0;} count = manager.getIntProperty(cname + ".count", 1);if (count <= 0) { count = 1;} append = manager.getBooleanProperty(cname + ".append", false);setLevel(manager.getLevelProperty(cname + ".level", Level.ALL));setFilter(manager.getFilterProperty(cname + ".filter", null));setFormatter(manager.getFormatterProperty(cname + ".formatter",new XMLFormatter()));try { setEncoding(manager.getStringProperty(cname +".encoding", null));} catch (Exception ex) { try { setEncoding(null); } catch (Exception ex2) {// doing a setEncoding with null should always work.// assert false; }} }
其中這行 說明預設不會追加log資料的
append = manager.getBooleanProperty(cname + ".append", false);
所以需要在logging.properties下配置一下
java.util.logging.FileHandler.append = true
到此問題解決
2: 注意logger.properties檔案中有這麼一句, 也就是說基本上不可以通過設定檔配置自訂Handler了
These handlers will be installed during VM startup.
# Note that these classes must be on the system classpath.
# "handlers" specifies a comma separated list of log Handler # classes. These handlers will be installed during VM startup.# Note that these classes must be on the system classpath.# By default we only configure a ConsoleHandler, which will only# show messages at the INFO and above levels.handlers= java.util.logging.ConsoleHandler, java.util.logging.FileHandler