How To Configure Apache Tomcat or Pivotal tc Server to rotate log files by size with logging.properties
search cancel

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

book

Article ID: 293333

calendar_today

Updated On:

Products

VMware Tanzu tc Server

Issue/Introduction

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

Environment


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

Resolution

Use the following procedure to rotate log files on an Apache Tomcat or on a Pivotal 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

    NoteLimit 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.