Spectrum tomcat web server logs are not being removed
search cancel

Spectrum tomcat web server logs are not being removed

book

Article ID: 369352

calendar_today

Updated On:

Products

DX NetOps CA Spectrum

Issue/Introduction

The tomcat and webtomcat logs are not rotating and archiving.

For webtomcat, the catalina.out log is not rotating, we are seeing entries going back over 60 days in the past when the install was done (our servers are rebooted every month, so webtomcat is restarted every month).

For both tomcat and webtomcat, we have the default log4j2 settings, however all the logs (ie catalina and localhost) are being retained for 3 months.

Environment

All supported DX NetOps Spectrum releases 23.3.4 and higher

Cause

Incorrectly configure log4j2.xml file installed with Spectrum OneClick tomcat web server

Resolution

To resolve this make the following changes to the $SPECROOT/tomcat/classes/log4j2.xml file.

  1. Create a backup of the existing $SPECROOT/tomcat/classes/log4j2.xml file.
  2. Open the log4j2.xml file for editing.
  3. Find this section for the <RollingFile name="CATALINA" entry. Change it as follows:

    <RollingFile name="CATALINA" fileName="${logDir}/catalina.out"
                        filePattern="${logDir}/catalina.%d{yyyy-MM-dd}.%i.log.gz">
          <PatternLayout pattern="${layout}"/>
          <Policies>
                  <OnStartupTriggeringPolicy minSize="25000"/>
                  <SizeBasedTriggeringPolicy size="1024MB"/>
                  <TimeBasedTriggeringPolicy/>
          </Policies>
          <DefaultRolloverStrategy max="10">
                 <Delete basePath="${logDir}" maxDepth="2">
                        <IfFileName glob="catalina.*.log.gz" />
                        <IfLastModified age="P30D" />
                 </Delete>
          </DefaultRolloverStrategy>
    </RollingFile>

  4. Save the changes to the file and restart the tomcat web server.
  5. Confirm the logs are cleaned up post restart, leaving only the last 30 days of logging.

Additional Information

Want to add log rotation for the localhost_access_log files as well?

  1. Create a backup of the existing $SPECROOT/tomcat/classes/log4j2.xml file.
  2. Open the log4j2.xml file for editing.
  3. Find this section for the <RollingFile name="LOCALHOST" entry.

     <RollingFile name="LOCALHOST" fileName="${logDir}/localhost.log"
                                             filePattern="${logDir}/localhost.%d{yyyy-MM-dd}.log.gz">
                            <PatternLayout pattern="${layout}"/>
                            <Policies>
                                    <SizeBasedTriggeringPolicy size="50MB"/>
                                    <TimeBasedTriggeringPolicy interval="1"/>
                            </Policies>
                            <DefaultRolloverStrategy max="15"/>
                    </RollingFile>
  4. Modify it or replace it entirely with the following XML.

    <RollingFile name="LOCALHOST" fileName="${logDir}/localhost.log"
                        filePattern="${logDir}/localhost_access_log..%d{yyyy-MM-dd}.txt">
        <PatternLayout pattern="${layout}"/>
        <Policies>
                <SizeBasedTriggeringPolicy size="50MB"/>
                <TimeBasedTriggeringPolicy interval="1"/>
                </Policies>
        <DefaultRolloverStrategy max="15">
                <Delete basePath="${logDir}" maxDepth="2">
                        <IfFileName glob="localhost_access_log*.txt" />
                        <IfLastModified age="P30D" />
                </Delete>
        </DefaultRolloverStrategy>
    </RollingFile>

  5. Save the changes to the log4j2.xml file.
  6. Restart tomcat.