[logback-user] RollingFileAppender with Prudent Flag

Thomas.Guenter1 at swisscom.com Thomas.Guenter1 at swisscom.com
Tue Aug 11 13:12:34 CEST 2009


Hi Ceki,

thanks for your answer in detail and sorry for missing the section in the documentation. I see your points and will look for alternatives.

Regards,
tom

-----Original Message-----
From: logback-user-bounces at qos.ch [mailto:logback-user-bounces at qos.ch] On Behalf Of Ceki Gulcu
Sent: Tuesday, August 11, 2009 12:32 PM
To: logback users list
Subject: Re: [logback-user] RollingFileAppender with Prudent Flag


Setting the File property to a non-null value implies that during rollover that file would need to be renamed and moved. However, when multiple processes have a file descriptor open (which is the intention in prudent mode), most operating systems won't allow moving of the file, hence the File=null restriction.

Ceki Gulcu wrote:
> 
> 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
> 
> Thomas.Guenter1 at swisscom.com 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
Logback-user at qos.ch
http://qos.ch/mailman/listinfo/logback-user


More information about the Logback-user mailing list