Problem: log4j.xml files not creating backups
Have you ever noticed that sometimes a log configured in log4j.xml is not rolling and getting archived as you would expect?
The likely culprit is that you are monitoring or tailing the log file. While you have an open handle on the log file, it is not able to copy it to archives even though you have configured it to do so.
For example if you run: tail -f xMatters.txt
That file will never get copied/archived. It will reset to 0 byes when it reaches the configured size limit in log4j.xml but not backups will be created.
If you have a log scraper program or anything that continuously monitors the log files you will notice this behavior.
Solution: Create seperate entry in your log4j.xml that you can monitor
Normally you would only have one entry like this for your txt log file:
<appender name="txtAppender" class="com.alarmpoint.integrationagent.log.APRollingFileAppender">
<param name="maxBackupIndex" value="10"/>
<param name="MaxFileSize" value="1000KB"/>
<param name="File" value="./log/xMatters.txt"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %p - %m%n"/>
</layout>
</appender>
A solution to this problem is that you can create a second log file (one that you will use to monitor or tail)
<appender name="txtAppender2" class="com.alarmpoint.integrationagent.log.APRollingFileAppender">
<param name="maxBackupIndex" value="0"/>
<param name="MaxFileSize" value="1000KB"/>
<param name="File" value="./log/xMatters-monitor.txt"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %p - %m%n"/>
</layout>
</appender>
This file "xMatters-monitor.txt" can be monitored/tailed all day long. The other file xMatters.txt will continue to log and backup as usual.
Be sure to add an entry at the bottom of log4j.xml with your new appender type:
<root>
<priority value ="WARN"/>
<appender-ref ref="txtAppender"/>
<appender-ref ref="xmlAppender"/>
<appender-ref ref="consoleAppender"/>
<appender-ref ref="txtAppender2"/>
</root>