codebox
codebox

Reputation: 20264

How to turn off all tomcat log rotation

I want to manage log rotation on my server using logrotate, however Tomcat performs its own log rotation which interacts badly with logrotate, and I can't find a way to turn it off. My Tomcat instance currently produces 5 types of log:

After some googling I have discovered that I can disable rotation for the 'mysite' logs by adding rotatable="false" into the appropriate <Value> element in server.xml, but none of the other logs have corresponding <Value> elements.

The logs seems to be configured by the logging.properties file, but I can't find a 'turn rotation off' option for this file. Can anyone help? I'm using Tomcat 8.5

Upvotes: 1

Views: 6092

Answers (2)

Rishikesh Darandale
Rishikesh Darandale

Reputation: 3310

There is option available in org.apache.juli.AsyncFileHandler to turn of the rotatable functionality. You can directly add following param to disable to log rotation:

1catalina.org.apache.juli.AsyncFileHandler.rotatable = false

Upvotes: 2

svarog
svarog

Reputation: 9847

The logs seems to be configured by the logging.properties file, but I can't find a 'turn rotation off' option for this file

You can try using a different log handler and configure it to avoid rotation

Your properties file probably holds this configuration (if you haven't changed the default settings)

1catalina.org.apache.juli.AsyncFileHandler.level = DEBUG
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.

You can change it to a java.util.logging.FileHandler and disable the size limit for a rotation

1catalina.java.util.logging.FileHandler.level = DEBUG
1catalina.java.util.logging.FileHandler.pattern = ${catalina.base}/logs/catalina.%g.log 

# set below limit to 0 !!
1catalina.java.util.logging.FileHandler.limit = 0
1catalina.java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter

From the docs

java.util.logging.FileHandler.limit

The maximum size of the file, in bytes. If this is 0, there is no limit. The default is 1000000 (which is 1 MB). Logs larger than 1MB roll over to the next log file

Since there is no limit, a file rotation will never occur.

Upvotes: 4

Related Questions