Clearing old logs from Web Viewer 14.0 filesystem Deleting
search cancel

Clearing old logs from Web Viewer 14.0 filesystem Deleting

book

Article ID: 214704

calendar_today

Updated On:

Products

Output Management Web Viewer

Issue/Introduction

Since installing Web viewer, our ZFS files are getting larger and larger, and it seems to be that log files are not being deleted in the .$CAWVHOME/logs/   directory sometimes creating an out of space condition. This is taking unnecessary disk space. Is there some option to delete or only retain for a set period or some housekeeping that has been over looked? 

 

Environment

Output Management Web Viewer™ for z/OS

Resolution

Note that log4j2 does have a method for deleting old log files via the DefaultRolloverStrategy – but it is not in the sample log4j2.xml file that is distributed. 

The log4j file is located at $CAWVHOME/config/log4j2.xml. Make a backup of your log4j2.xml file before making any changes. These files in USS are ASCII files. Use ISPF option 3.17 to EA (Edit ASCII).

Here is a sample DefaultRolloverStrategy that deletes log files after 50 days:  

<DefaultRolloverStrategy max="14">                   

    <Delete basePath="${logPath}/" maxDepth="1">     

         <IfFileName glob="*.log" />                 

         <IfLastModified age="50d" />                

    </Delete>                                         

</DefaultRolloverStrategy>

 

The 50 days comes from age=”50d” which can be changed.

Note that this only gets triggered when the day rolls over, if you want it triggered at startup time as well, add OnStartupTriggeringPolicy as a Policy.  For example:-

<Policies>                                           

    <OnStartupTriggeringPolicy/>                    

    <TimeBasedTriggeringPolicy/>                      

    <!-- <SizeBasedTriggeringPolicy size="1 KB" /> -->

</Policies>

 
This deletes log files based on age but it is also possible to configure it to delete based on accumulated space, See Delete If Accumulated File Size.
 
When you start up your Tomcat task you will be able to verify policy changes are in effect from the Status Logger messages in the Tomcat started task log after you recycle the task.

Additional Information

IMPORTANT: Log4j2 only does the clean-up when the policy is triggered.  According to the log4j documentation, <TimeBasedTriggeringPolicy/> means the policy will be triggered once the date/time pattern no longer applies to the active file.  Since Web Viewer only calls log4j when a log message is issued that means the date has to change and a log message has to be written – if there is no activity in Web Viewer and no log records are being written then the policy will not be triggered.

 To force the policy to be triggered at start-up (ie when the first log record is written) you will need to add <OnStartupTriggeringPolicy /> in <Policies>.

see the official Apache Log4j Documentation.

 

Sample log4j2.xml file:

Configuration status="OFF">                                                                                
    <!-- Switch configuration status to receive logging message related to processing this file. -->            
    <Properties>                                                                                            
        <Property name="logPath">${env:CAWVHOME}/logs                                                      
        </Property>                                                                                        
        <Property name="logName">${web:contextPath}                                                        
        </Property>                                                                                        
        <Property name="springUser">*Spring                                                                
        </Property>                                                                                        
        <Property name="springSessionId">1                                                                  
        </Property>                                                                                        
        <Property name="rootLogLevel">info                                                                  
        </Property>                                                                                        
        <Property name="springLogLevel">info                                                                
        </Property>                                                                                        
        <Property name="contentViewerLogLevel">info                                                        
        </Property>                                                                                        
    </Properties>                                                                                          
    <Appenders>                                                                                            
       <Console name="STDOUT" target="SYSTEM_OUT">                                                            
           <PatternLayout>                                                                                    
               <!-- <pattern>%d{DEFAULT} %-5p %m%n</pattern> -->                                              
               <pattern>%d{DEFAULT} %-5p &lt;%X{userid}&gt; &lt;%X{sessionid}&gt; %m%n</pattern>              
               <charset>UTF-8</charset>                                                                      
           </PatternLayout>                                                                                  
       </Console>                                                                                            
       <RollingFile name="RollingFile" fileName="${logPath}/${logName}.log"                                    
           filePattern="${logPath}/${logName}-%d{yyyy-MM-dd}-%i.log">                                          
           <PatternLayout>                                                                                    
               <!-- <pattern>%d{DEFAULT} %-5p (%F:%L) %m%n</pattern> -->                                      
               <pattern>%d{DEFAULT} %-5p &lt;%X{userid}&gt; &lt;%X{sessionid}&gt; %m%n</pattern>              
           </PatternLayout>                                                                                  
           <Policies>                                                                                        
               <TimeBasedTriggeringPolicy/>                                                                  
               <!-- <SizeBasedTriggeringPolicy size="1 KB" /> -->                                            
           </Policies>                                                                                        
           <DefaultRolloverStrategy max="14" >                                                              
                <Delete basePath="${logPath}/" maxDepth="1">                                                
                     <IfFileName glob="*.log" />                                                              
                     <IfLastModified age="14d" />                                                        
                </Delete>                                                                                
           </DefaultRolloverStrategy>                                                                    
       </RollingFile>                                                                                    
       <Rewrite name="rewriteSpring">                                                                    
           <AppenderRef ref="RollingFile" />                                                              
           <AppenderRef ref="STDOUT"/>                                                                    
           <PropertiesRewritePolicy>                                                                      
               <Property name="userid">${springUser}</Property>                                          
               <Property name="sessionid">${springSessionId}</Property>                                  
           </PropertiesRewritePolicy>                                                                    
       </Rewrite>                                                                                        
   </Appenders>                                                                                          
   <Loggers>                                                                                              
       <Logger name="org.springframework" level="${springLogLevel}" additivity="false">                  
           <AppenderRef ref="rewriteSpring" />                                                            
       </Logger>                                                                                          
       <Logger name="com.ca.om.contentviewer" level="${contentViewerLogLevel}" additivity="false">        
           <AppenderRef ref="RollingFile" />                                                              
           <AppenderRef ref="STDOUT" />                                                                  
        </Logger>                                                          
        <Root level="${rootLogLevel}" additivity="false">                  
            <AppenderRef ref="RollingFile" />                              
            <AppenderRef ref="STDOUT" />                                    
        </Root>                                                            
    </Loggers>                                                              
</Configuration>