1
votes

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:

  • catalina.2018-01-17.log
  • mysite_access.2018-01-17.log
  • localhost.2018-01-17.log
  • host-manager.2018-01-17.log
  • manager.2018-01-17.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

2
Same question on serverfault for reference: serverfault.com/questions/892824/… - codebox

2 Answers

3
votes

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.

1
votes

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