Pivotal Knowledge Base

Follow

How To Configure Apache Tomcat 6.0/7.0 or tc Server to rotate log files by size with logging.properties

Environment
 
Product   Version
Apache Tomcat 6.0 or 7.0                     
VMware vFabric tc Server  
 
Purpose

This article describes an alternative configuration mode that allows log files to be rotated by file size rather than by the date.

Cause

By default, Apache Tomcat and vFabric tc Server uses a custom implementation of java.util.logging. The custom implementation is called JULI and is the default logging mechanism for the Apache Tomcat and tc Server. 
 
The default configuration of JULI rotates log files by date, resulting in the following file name conventions: catalina.yyyy-mm-dd.log or localhost.yyyy-mm-dd.log

Procedure

Use the following procedure to rotate log files on an Apache Tomcat or on a vFabric tc Server:
  1. The org.apache.juli.FileHandler class does not support rotating files by size. Change any references to org.apache.juli.FileHandler to java.util.logging.FileHandler. This FileHandler implementation does support rotating files by size. A simple find and replace on the conf/logging.properties file should be sufficient.

  2. Because you are using the java.util.logging.FileHandler implementation, you must adjust the properties which configure the FileHandler. Look for the section of the conf/logging.properties file that starts with the following:

    ############################################################
    # Handler specific properties.
    # Describes specific configuration info for Handlers.
    ############################################################

  3. In this section, delete any lines that configure directory or prefix. These properties do not exist on the java.util.logging.FileHandler.

    For example:


    1catalina.java.util.logging.FileHandler.directory = ${catalina.base}/logs
    1catalina.java.util.logging.FileHandler.prefix = catalina.

  4. In the same section of conf/logging.properties, add the following lines for each FileHandler. Replace 1catalina with the name of each FileHandler to use a unique file name for the pattern property.

    1catalina.java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
    1catalina.java.util.logging.FileHandler.pattern = ${catalina.base}/logs/catalina.%g.log
    1catalina.java.util.logging.FileHandler.limit = 100000
    1catalina.java.util.logging.FileHandler.count = 5

    Note: Limit defines the size in KB at which the log file is rotated. Count defines how many archive files are maintained.


  5. Save conf/logging.properties and restart your Tomcat or tc Server instance.
The new log rotation scheme should now be active. For reference, included with this article is an example logging.properties which includes the changes referenced in this article.

Additional Information

©VMware 2013

Comments

  • Avatar
    Binh Nguyen

    Thanks, nice tips

Powered by Zendesk