Tomcat Log Management on Windows

As part of its normal operation Tomcat creates and writes information to a set of log files.

Unless periodically purged, these files accumulate and consume valuable space. It is commonly accepted by the IT community that the informational value those logs provide degrades rapidly. Unless other factors like regulations or compliance with certain policies play, keeping those log files in the system a discrete number of days is what is required.

Introduction:

As part of its normal operation Tomcat creates and writes information to a set of log files. On Windows, these files are normally located in the following directory:

C:\Program Files (x86)\Acronis\Access\Common\apache-tomcat-7.0.34\logs
Acronis Access saves it's own logs in the same directory as separate files.

Acronis Access's log files are named acronisaccess_date.

There are many tools capable of automating the task of deleting unneeded log files. For our example, we will use a built-in Windows command called ForFiles.

Info: For information on ForFiles, syntax and examples visit http://technet.microsoft.com/en-us/library/cc753551(v=ws.10).aspx

A sample process:

The sample process described below automates the process of purging log files older than a certain number of days. Inside the sample batch file, this number is defined as a parameter so it can be changed to fit different retention policies.

Info: The sample script (batch) file is designed to work on Windows 2003 and Windows 2008. Click here to download the script.
Optionally you could copy and paste the script code into an empty text document and save it as “AASTomcatLogPurge.bat”

Click here for the full batch script code...

Warning: We provide this example as a guideline so you can plan and implement your own process based on the specifics of your deployment. The example is not meant nor tested to apply to all situations and environments so use it as a foundation and at your own risk. Do not use it in production environments without comprehensive offline testing first.

Steps:

  1. Copy the script to the computer running Acronis Access (Tomcat) and open it with Notepad or a suitable plain text editor.
  2. Locate the section illustrated in the picture below and edit the LogPath and NumDays variables with your specific paths and retention settings:

    TomcatLogs Step2

    In Acronis Access the log files are stored in the same folder as Tomcat's. (C:\Program Files (x86)\Acronis\Access\Common\apache-tomcat-7.0.34\logs)

  3. Save the file.
  4. To automate the process, open Task Scheduler and create a new task. Define a name and a description for the task.
    TomcatLogs Step4
  5. Set the task to run daily.
    TomcatLogs Step5
  6. Define at what time the task should start. It is recommended to run this process when the system is not under extreme load or other maintenance processes are running.
    TomcatLogs Step6
  7. Set the action type to “Start a program”.
    TomcatLogs Step7
  8. Click the Browse button, locate and select the script (batch) file.
    TomcatLogs Step7
  9. When done, click Finish.
    TomcatLogs Step9
  10. In the tasks list you may want to right click on the task, select properties and verify the task will run whether a user is logged on or not, for unattended operation.
  11. You can verify the task is properly configured and running properly by selecting the task, right clicking on it and selecting “Run”. The scheduler’s log should report start, stop and any errors.