[logback-user] RollingFileAppender with Prudent Flag
Thomas.Guenter1 at swisscom.com
Thomas.Guenter1 at swisscom.com
Tue Aug 11 11:01:04 CEST 2009
Hi,
we're using logback and the RollingFileAppender to write log files from several webservice to a /logs directory and automatically move "old" files into a /logs/archive directory based on a TimeBasedRollingPolicy. This works great with the following configuration:
<appender name="SERVICE_CALL_SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator class="com.myproject.logback.ContextEnvironmentPartBasedDiscriminator">
<DefaultValue>unknown</DefaultValue>
</discriminator>
<sift>
<appender name="FILE-AUDIT-${environmentName}" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_DIR}/service_call_${environmentName}.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Rollover at midnight. Put log as uncompressed file to archive. -->
<FileNamePattern>${LOG_DIR}/archive/service_call_${environmentName}_%d{yyyy-MM-dd}.log</FileNamePattern>
<!-- Keep 5 days worth of history -->
<MaxHistory>${MAX_HISTORY_DAYS}</MaxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%contextName] refId: %mdc{refId}, %msg%n</Pattern>
</layout>
</appender>
</sift>
</appender>
But since some of the log files are shared between different applications, I discovered some strange effects (one of the applications stopped writing into one of the log-files) and read about the prudent flag. Now, I tried to switch on the prudent mode using the following configuration:
<appender name="SERVICE_CALL_SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator class="com.myproject.logback.ContextEnvironmentPartBasedDiscriminator">
<DefaultValue>unknown</DefaultValue>
</discriminator>
<sift>
<appender name="FILE-AUDIT-${environmentName}" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_DIR}/service_call_${environmentName}.log</File>
<!-- Ensure safe writing to one log file from different contexts by setting prudent to true -->
<Prudent>true</Prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Rollover at midnight. Put log as uncompressed file to archive. -->
<FileNamePattern>${LOG_DIR}/archive/service_call_${environmentName}_%d{yyyy-MM-dd}.log</FileNamePattern>
<!-- Keep 5 days worth of history -->
<MaxHistory>${MAX_HISTORY_DAYS}</MaxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%contextName] refId: %mdc{refId}, %msg%n</Pattern>
</layout>
</appender>
</sift>
</appender>
This way, the node /appender/sift/appender/File isn't used anymore and the logger directly writes into the archive file specified under /appender/sift/appender/rollingPolicy/FileNamePattern.
Is there a way of using the prudent mode but still separating the log from the archive files?
Thanks for your help!
tom
More information about the Logback-user
mailing list