(7.6+) Tomcat log rolling
- Do not utilize log4j versions lower than 2.15. For upgrade instructions, see Updating log4j 2.x to 2.16+ for enhanced security.
- Make sure the user accounts used in this process have permission to update and delete files in the Tomcat installation directory.
- Back up any files or directories listed in this article before making changes.
- Stop the Tomcat service before making changes to configuration files.
Standalone VIS on Linux
Use the following instructions to configure log rolling on a Linux server.
Update configuration on Linux
- Stop the Tomcat service
- Back up and delete the existing tomcat-juli.jar file from <Tomcat_install_path>/bin.
- Back up and delete the existing logging.properties file from <Tomcat_install_path>/conf.
- Copy the new tomcat-juli.jar file to <Tomcat_install_path>/bin.
- Copy the new tomcat-juli-adapters.jar file to <Tomcat_install_path>/lib.
- Edit the new log4j2.xml file:
- Update the following subtags within the <RollingFile> tagas desired:
- SizeBasedTriggeringPolicy - Maximum file size before creating a new log file
- DefaultRolloverStrategy - Maximum number of files to keep
- Update the following subtags within the <RollingFile> tagas desired:
- Copy the updated log4j2.xml file to <Tomcat_install_path>/lib.
- Copy the following new JAR files to <Tomcat_install_path>/lib
- log4j-api-2.15.0.jar
- log4j-core-2.15.0.jar
- log4j-jul-2.15.0.jar
- Edit the <Tomcat_install_path>/conf/server.xmlfile to enable Tomcat access logs.
- Update <VALVE> tag with the following (Where the value for maxDays is the maximum number of days to keep logs):
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" rotatable ="true" fileDateFormat=".yyyy-MM-dd" maxDays="30" pattern="%h %l %u %t "%r" %s %b" />
Edit the <Tomcat_install_path>/conf/content.xml file to add swallowOutput="true" in the <Context> tag:
<Context swallowOutput="true" >
Start the Tomcat service.
Standalone VIS on Windows Server
Use the following instructions to configure log rolling on Windows Server.
The default Tomcat installation directory on Windows Server is \\Program Files\Apache Software Foundation\Tomcat<version>.
Access logs
Tomcat access logs are written to the server.xml file, located at <InstallationPath>\conf by default. These logs can be rotated daily, but old log files cannot be automatically deleted. Log deletion must be handled by the system administrator via a scheduled batch script or the administrator's preferred method.
Rotate access logs daily
Quick access: <InstallationPath>\conf\server.xml
- In the server.xml file, update the <valve> tag as shown in the following example.
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" />
- Restart the Tomcat service
Access logs can also be disabled entirely, preventing the need to address older log files.
Disable access logs
Quick access: <InstallationPath>\conf\server.xml
- In the server.xml file, use HTML comment tags (<!-- and -->) to disable the <valve> tag entirely. See the following example for reference.
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" />
-->
- Restart the Tomcat service.
Console and common-daemon logs
Tomcat uses the stdout and stderr files, as well as the common-daemon logs, for general console logging. On Windows Server operating systems, the log4j mechanism cannot be used the same way as it can on a Linux system to manage these logs. Additionally, these logs cannot be automatically cleaned based on the file size or age.
The stdout and stderr console logs, as well as the common-daemon logs, are not required in production environments. As such, we recommend disabling these logs altogether.
Disable console and common-daemon logs
Quick Access: <Installationpath>\bin\tomcat9w.exe
- Run tomcat9w.exe, located at <Installationpath>\bin by default. This will open the Tomcat configuration wizard.
- Click Stop in the General tab.
- Open the Logging tab, then remove the values in the Log path and Log prefix fields. Keep these boxes empty to disable common-daemon logging.
- Remove the word auto in the Redirect Stdout field. Keep this box empty to disable stdout logging.
- Remove the word auto in the Redirect Stderror field. Keep this box empty to disable stderr logging.
- Click Apply.
Quick Access: <Installationpath>\conf\context.xml
In the context.xml file (located at <InstallationPath>\conf by default), update the <Context> tag as shown in the following example.
<Context swallowOutput="true">
Start the Tomcat service.
Application logs
Application-level logging is written to various log files, including catalina, host-manager, and manager. The log4j mechanism can be used to rotate and delete these files based on file size, age, and count.
Try it: Manage application logs:
- Download Standalone VIS - Windows.zip and extract the contents onto the Tomcat server.
- Stop the Tomcat service.
- Remove the existing logging.properties file located at <InstallationPath>\conf\logging by default.
- Copy the following extracted files to the <InstallationPath>\lib directory. If any of these files already exist, replace them with the new versions.
- log4j2.xml
- log4j-jul-2.15.0.jar
- log4j-api-2.15.0.jar
- log4j-core-2.15.0.jar
- tomcat-juli-adapters.jar
By default, log4j.xml is configured to rotate when log files reach 10 MB in size, and to keep a maximum of 100 files before deleting the oldest. The log4j.xml file can be updated to adjust these values.
The following sample shows default configuration for the Catalina logs.
<RollingFile name="CATALINA" fileName="${logdir}/catalina.out" filePattern="${logdir}/catalina.%i.out">
<PatternLayout pattern="${layout}"/>
<Policies>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
<DefaultRolloverStrategy max="100"/>
</RollingFile
Copy the setenv.bat file to the <InstallationPath>\bin directory.
Quick Access: <Installationpath>\bin\tomcat9w.exe
- Run tomcat9w.exe, located at <Installationpath>\bin by default. This will open the Tomcat configuration wizard.
- In the Java table, update the value of the Java Classpath variable as shown in the following example.
<InstallationPath>\bin;<InstallationPath>\lib;<InstallationPath>\bin\bootstrap.jar;<InstallationPath>\bin\tomcat-juli.jar;<InstallationPath>\lib\tomcat-juli-adapters.jar;<InstallationPath>\lib\log4j-core-2.15.0.jar;<InstallationPath>\lib\log4j-api-2.15.0.jar;<InstallationPath>\lib\log4j-jul-2.15.0.jar
The following example shows the complete value of the Java Classpath variable, based on the default Tomcat installation path.
C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin;
C:\Program Files\Apache Software Foundation\Tomcat 8.5\lib;
C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin\bootstrap.jar;
C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin\tomcat-juli.jar;
C:\Program Files\Apache Software Foundation\Tomcat 8.5\lib\tomcat-juli-adapters.jar;
C:\Program Files\Apache Software Foundation\Tomcat 8.5\lib\log4j-core-2.15.0.jar;
C:\Program Files\Apache Software Foundation\Tomcat 8.5\lib\log4j-api-2.15.0.jar;
C:\Program Files\Apache Software Foundation\Tomcat 8.5\lib\log4j-jul-2.15.0.jar
- In the Java Options text box, update the Djava.util.logging.manager and Djava.util.logging.config.file variables as shown in the following example.
Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManagerDjava.util.logging.config.file=<InstallationPath>\lib\log4j2.xml
Quick Access: C:/VirtualHold/toolkit.properties- Open the toolkit.properties file for the VIS application, located at C:/VirtualHold/ by default.
- Update external.mediaserver.logging to none as shown in the following example.
external.mediaserver.logging=none
- Start the Tomcat service using the tomcat9w.exe application.
VIS installed through IVG
Tomcat installed with IVG is already configured for log rolling. However, Tomcat access logs are disabled. Use the following instructions to enable access logs and their rolling mechanism.
Enable access logs
- Stop the Tomcat service.
- Edit the <Tomcat_install_path>/conf/server.xmlfile to enable access logs of tomcat:
- Update <VALVE> tag with the following:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" rotatable ="true" fileDateFormat=".yyyy-MM-dd" maxDays="30" pattern="%h %l %u %t "%r" %s %b" />
- Update <VALVE> tag with the following:
Where the value for maxDays is the maximum number of days to keep logs.
If the <VALVE> tag is commented, uncomment and update it.
Start the Tomcat service.