How to enable file rotation to periodically purge older log files and clear space using the default juli internal logging for Apache Tomcat.
By default, Apache Tomcat dies its internal logging through juli. The quantity of information stored in the log files on any server can quickly grow to be quite large. For instance, the access log file typically grows 1 MB or more per 10,000 requests. Therefore, it may be necessary to periodically rotate the log files by moving the files or deleting the existing logs to free up space on the server and allow for more efficient searching through logs. This cannot be done while the server is running, because Apache Tomcat will continue writing to the old log file as long as it holds the file open.
To achieve this, in the logging.properties, add:
.handlers = 1catalina.java.util.logging.FileHandler
.level=FINE
1catalina.java.util.logging.FileHandler.level = FINE
1catalina.java.util.logging.FileHandler.pattern = ${catalina.base}/logs/${catalina.appserver.instance}.%g.log
1catalina.java.util.logging.FileHandler.limit = 2000000
1catalina.java.util.logging.FileHandler.count = 5
1catalina.java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatterwhere 1catalina.java.util.logging.FileHandler would instantiate the FileHandler that comes with JDK.
Since java.util.logging.FileHandler does not have .prefix or .directory, .prefix and .directory needs to be set in the catalina package:
1catalina.java.util.logging.FileHandler.pattern = ${catalina.base}/logs/catalina.%g.log NOTE: The names have to be consistent everywhere, including in the handlers and .handlers references.
For further details, the JDK filehandler is documented at: http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/FileHandler.html
Popular Links
Comments
The "<handlers></handlers>"
The "<handlers></handlers>" seems confusing. Perhaps using the normal comment syntax is more appropriate:
Thanks
Thanks for spotting that. Looks like a copy/paste error. I've fixed the logging.properties extract by removing those tags.Time based log file rotation
Using JULI how would you configure log file rotation on daily or hourly basis.
Post new comment