I have problem with space so need limit size of catalina.out to 10M and limit number of rolls to 3 previous days. Is it possible with only configure logging.properties? Thanks.
-
I know this is an old post, but as I prefer to have all the answers in this site, I'll just add that you can also follow [this alternative](http://java.dzone.com/articles/how-rotate-tomcat-catalinaout). It is very easy to implement in Unix machines – Edu Castrillon Jul 11 '14 at 07:52
-
Combining days and size is not handled by most property based logging configurations, and the combination isn't always intuitive. A sized based log file may span moments or months. If you have a size target, then a size * number of rotations keeps you in that limit. If you need to keep X days, then you may need to allow for more space. – jla Sep 21 '18 at 22:03
2 Answers
As Tomcat internally uses JUL to log , you can use the system property java.util.logging.config.file
to specify the file path of the properties file. For the format of this properties file , you can refer to your JRE_HOME/lib/logging.properties
(which is the default configuration file used by JUL)
However, JUL does not support the daily rotation . If you don't mind , you can use its java.util.logging.FileHandler
to rotate the log files based on the log 's file size instead:
# Define the FileHandler
handlers= java.util.logging.FileHandler
# Configure the FileHandler
java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 1024000
java.util.logging.FileHandler.count = 3
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.append=true
Then , each log file will has the limit size 1024000 bytes (1MB) , and maximum roll to 3 output log files . You can refer the Javadoc of java.util.logging.FileHandler for the details about the configuration.
You have to implemnt the File Handler if you want to support rotation on daily basis using JUL . I found a custom implemenation from this blog . I did not try it yet. You can refer it if you have any interest.

- 84,777
- 26
- 143
- 172
-
1
-
Yes , you are right.I misread the question. JUL seems does not have built-in handler to rotate the log daily. – Ken Chan Dec 01 '11 at 16:05
-
4Why set the limit at 2^10*1000, that seems a bit random? Why not 1MB (1000000 bytes) or 1MiB ( 2^20 / 1048576 bytes) – dan carter Nov 10 '13 at 22:35
-
When using rotation, you might want to use %g: '"%g" the generation number to distinguish rotated logs' – mateuszb Nov 26 '13 at 08:17
-
How do you rotate tomcat access logs(localhost_access*) based on size ? – Balaji Boggaram Ramanarayan Aug 08 '14 at 00:22
-
Is it okay to specify this in logging.properties files in Tomcat's conf directory? – Dojo Sep 19 '14 at 16:39
Since at least Tomcat 5.5 "the internal logging for Apache Tomcat uses JULI, a packaged renamed fork of Apache Commons Logging that is hard-coded to use the java.util.logging (JUL) framework."
Recent versions of JULI and the Access Log Valve by-default use a YYYY-MM-dd date format. The juli.FileHandler logs are named {prefix}{date}{suffix} where date is yyyy-MM-dd if rotatable is true (default). If false, the date is dropped and Tomcat will not handle file rotation. There is also a maxDays parameter to limit the number of those Tomcat rotated logs that will be kept. You could for example set that to 3 and only have three days worth of logs kept.
The Access Log Valve is more configurable. For example it let you specify a fileDateFormat from the default of yyyy-MM-dd, so you could add HH to rotate every hour, or just rotate monthly. You can also choose to delay the formatted naming until rotation with renameOnRotate.
If you need something fancier than this or JUL's size and count based rotation, it may be best to set rotatable to false and handle rotation externally to Tomcat.

- 6,904
- 2
- 36
- 34