tomcat 日誌 java.util.logging.Logger使用 (四)

來源:互聯網
上載者:User

今天將寫好的代碼放到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


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.