Hello Thomas,

The File property of RollingFileAppender cannot be set in prudent
mode. This is documented in [1] (see the table describing the
properties of RollingFileAppender). Moreover, the application of this
restriction should have been reported via logback's status
messages. The restriction is justified by technical reasons which
somehow I can no longer recall. Let me reconsider the issue and come
back to you.

[1] http://logback.qos.ch/manual/appenders.html#RollingFileAppender

[email protected] wrote:
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

--
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
_______________________________________________
Logback-user mailing list
[email protected]
http://qos.ch/mailman/listinfo/logback-user

Reply via email to