[logback-user] TimeBasedRollingPolicy - old logs present in current file

Pradnya Gawade pradnya.gawade7 at gmail.com
Thu Mar 10 21:45:17 CET 2011


Hi,

I am trying with this for a long time but could not figure out the problem.
My web application has to log to a log file but we want different
category tags to be assigned to the logs from specific packages,
although all log will go to the same physical log file. I create one
appender per category with the required tag included in the encoder
pattern. I have crated a filter per appender so it will only take the
logs for that category and reject all other logs.Then I map the parent
package of my web application source code with all the appenders that
I have created for each category. I know this sounds complicated
please bear with me. The category mapping I get in the logging is fine
and as expected but I am facing other unexpected issue of files
rolling over. I am using daily rollover policy. File gets rolled over
properly but the current log file contains a copy of logs from
archived file with new logs appended to it. I don't understand why it
happens.
I use o.9.20 version of logback. File rollover used to work fine
before I categorized the log and when all the logs simply used to go
to the same file without any category tagging associated.
Please suggest what could be going wrong if you can think of some
thing. Thanks in advance.

My logback.xml looks like:

<!-- appender for category LPR -->
	<appender name="LOGFILE-LPR"
class="ch.qos.logback.core.rolling.RollingFileAppender">
		<filter class="abc.log.LogFilterFacilityLPR"/>
		<file>${log.dir}.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<!-- daily rollover -->
			<fileNamePattern>${log.dir}.%d{yyyy-MM-dd}.log</fileNamePattern>
			<!-- keep 30 days' worth of history -->
			<maxHistory>30</maxHistory>
		</rollingPolicy>
		<encoder>
			<pattern>%date{MM/dd HH:mm:ss} [%mdc{WEBAPP}] LPR %-5level
%logger{25}:%L - %msg %n %ex{full}</pattern>
		</encoder>
	</appender>
	<!-- appender for category USER -->
	<appender name="LOGFILE-USER"
class="ch.qos.logback.core.rolling.RollingFileAppender">
		<filter class="abc.log.LogFilterFacilityUSER"/>
		<file>${log.dir}.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<!-- daily rollover -->
			<fileNamePattern>${log.dir}.%d{yyyy-MM-dd}.log</fileNamePattern>
			<!-- keep 30 days' worth of history -->
			<maxHistory>30</maxHistory>
		</rollingPolicy>
		<encoder>
			<pattern>%date{MM/dd HH:mm:ss} [%mdc{WEBAPP}] USER %-5level
%logger{25}:%L - %msg %n %ex{full}</pattern>
		</encoder>
	</appender>
.
.
.
.
<!-- logger for parent package -->
<logger additivity="false" name="org.akaza.openclinica">
		<level value="${logLevel}" />	
		<appender-ref ref="LOGFILE-OTHER"/>
		<appender-ref ref="LOGFILE-LPR"/>
		<appender-ref ref="LOGFILE-USER"/>
		<appender-ref ref="LOGFILE-MAIL"/>
		<appender-ref ref="LOGFILE-AUTH"/>
		<appender-ref ref="LOGFILE-UUCP"/>					
		<appender-ref ref="LOGFILE-AUTHPRIV"/>				
</logger>


More information about the Logback-user mailing list