[LOGBack-user] Unable to use RollingFileAppender

Ceki Gülcü listid at qos.ch
Thu Sep 14 22:18:13 CEST 2006


Hello Samuel,

I'd try the following. (Apologies, I did not have time to test it, so
it might contain minor mistakes.)

   <appender name="bitranlog" 
class="ch.qos.logback.core.rolling.RollingFileAppender">
     <rollingPolicy 
class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
       <param name="ActiveFile" value="bitran.log" />
       <param name="FileNamePattern" value="bitran.%i.log" />
       <param name="MinIndex" value="1" />
       <param name="MaxIndex" value="3" />
     </rollingPolicy>

     <triggeringPolicy 
class="ch.qos.logback.core.rolling.SizeBasedRollingPolicy">
       <param name="MaxFileSize" value="5MB" />
     </triggeringPolicy>

     <layout class="ch.qos.logback.classic.PatternLayout">
       <param name="pattern" value="%-4relative [%thread] %-5level %class - 
%msg%n" />
     </layout>
   </appender>

The TimeBasedRollingPolicy based example that you would usually want
to use in real life (instead of the above) is less verbose, and just as 
powerful.

   <appender name="FILE" 
class="ch.qos.logback.core.rolling.RollingFileAppender">
     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
       <param name="FileNamePattern" value="foo_%d{yyyy-MM}.log".zip />
       <param name="ActiveFileName" value="foo.log" />
     </rollingPolicy>
     <layout class="ch.qos.logback.classic.PatternLayout">
       <param name="Pattern" value="%-4relative [%thread] %-5level %class - 
%msg%n" />
     </layout>
   </appender>

You might also want to have a look at the javadocs.

http://logback.qos.ch/apidocs/ch/qos/logback/core/rolling/SizeBasedTriggeringPolicy.html
http://logback.qos.ch/apidocs/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.html
http://logback.qos.ch/apidocs/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.html

If you run into problems, please let us know.


At 08:24 PM 9/14/2006, Samuel Doyle wrote:
>Hi, using this it is now complaining about a triggeringpolicy.
>
>INFO in ch.qos.logback.core.joran.action.AppenderAction - About to 
>instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
>INFO in ch.qos.logback.core.joran.action.AppenderAction - Appender named 
>as [bitranlog]
>ERROR in ch.qos.logback.core.joran.action.NestedComponentIA - Could not 
>create component <rollingPolicy>.
>WARN in ch.qos.logback.core.rolling.RollingFileAppender[bitranlog] - 
>Please set a TriggeringPolicy for the RollingFileAppender named bitranlog
>INFO in ch.qos.logback.core.joran.action.AppenderAction - Popping appender 
>named [bitranlog] from the object stack

-- 
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://ceki.blogspot.com/




More information about the Logback-user mailing list