I am working on a grails application which was previously hosted on JBoss, but now we have moved to Apache Tomcat.
The Grails app on JBoss using log4j works perfectly, but we are facing a problem with the org.apache.log4j.DailyRollingFileAppender as we are using log4j in Apache Tomcat for both application logging and server logging.
The issue is that org.apache.log4j.DailyRollingFileAppender overwrites the old backup log files (e.g. we get log of date 9 in log of date 8 and no log of 8 found) and sometimes it starts logging in the previous day's backup file.
I don't know what the problem is with this appender since on JBoss they wrote org.jboss.logging.appender.DailyRollingFileAppender wrapper. Is there any issue with org.apache.log4j.DailyRollingFileAppender? Could you please suggest a solution?
<appender class="org.apache.log4j.DailyRollingFileAppender" name="FILE">
<errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
<param name="Threshold" value="INFO"/>
<param name="File" value="${catalina.base}/logs/applog.log"/>
<param name="Append" value="true"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS Z} level=%-5p class=%c %X{uniqueId} %X{hostname} %X{requestURI} %X{clientIP} %X{userId} %X{realmId} %X{sessionId} %X{locale} %X{callingHost} %X{uniqueIdCallingHost} %X{asyncUserId} %X{isAsync} %X{taskId} %m%n"/>
</layout>
</appender>
Since this was not working we use org.apache.log4j.rolling.RollingFileAppender using log4j's "extras" library. Below is the appender configuration but it still does not work properly.
<appender name="ROLL" class="org.apache.log4j.rolling.RollingFileAppender">
<param name="File" value="${catalina.base}/logs/paymentRolling.log" />
<param name="Threshold" value="INFO"/>
<param name="Append" value="true"/>
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="${catalina.base}/logs/appRolling.log.%d{yyyy-MM-dd}"/>
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS Z} level=%-5p class=%c %X{uniqueId} %X{hostname} %X{requestURI} %X{clientIP} %X{userId} %X{realmId} %X{sessionId} %X{locale} %X{callingHost} %X{uniqueIdCallingHost} %X{asyncUserId} %X{isAsync} %X{taskId} %m%n"/>
</layout>
</appender>