-1
我正在研究將信息和錯誤記錄器作爲日誌供我們參考的文本文件寫入的Java應用程序。該文件正在大幅增長,所以我需要檢查文件的大小...例如,如果文件大小超過10 Mb,我必須創建另一個文件。在使用tomcat server.xml或web.xml創建新日誌之前備份日誌文件
像這樣,我必須創建10個文件,一個接一個地旋轉,直到10個文件。達到10個文件後,我必須刪除開始文件並重新開始創建...
如何刪除文件後的否。的文件將成爲10?
此操作的主要限制是試圖在不使用log4j或logback庫的情況下完成要求。
Logging.properties
1catalina.org.apache.juli.AsyncFileHandler.level = FINE
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
2localhost.org.apache.juli.AsyncFileHandler.level = FINE
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
3manager.org.apache.juli.AsyncFileHandler.level = FINE
3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.
4host-manager.org.apache.juli.AsyncFileHandler.level = FINE
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.AsyncFileHandler
您是否在使用第三方API(如log4j)? – Ele
即使你不想使用log4j,你也可以看看它的源代碼:http://grepcode.com/file/repo1.maven.org/maven2/log4j/log4j/1.2.15/org/apache/ log4j/RollingFileAppender.java – StephaneM
包含一些日誌代碼和/或配置文件。 – jmehrens