今天将写好的代码放到ubuntu上测试,发现了几个问题。
1:每次svn update源码,tomcat重新部署以后 log 文件会消失~~
查看源码发现:
java.util.logging.FileHandler private 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