[LOGBack-user] Unable to use RollingFileAppender

Sebastien Pennec sebastien at qos.ch
Wed Sep 13 14:38:50 CEST 2006


Hello Samuel,

Thanks for trying logback!

The RollingFileAppender needs a TriggeringPolicy object to know when to roll the 
active output file.
In brief, a TriggeringPolicy controls the conditions under which roll-over occurs. 
Such conditions include time of day, file size, an external event, the log request or 
a combination thereof.

A working configuration file for a RollingFileAppender would be:

<configuration>
   <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
     <param name="File" value="/path/to/your/file.log"/>
     <rollingPolicy class="ch.qos.logback.core.rolling.SizeBasedRollingPolicy">
       <param name="MaxFileSize" value="5MB" />
     </rollingPolicy>
     <layout class="ch.qos.logback.classic.PatternLayout">
       <param name="Pattern" value="%-4relative [%thread] %-5level %class - %msg%n" />
     </layout>
   </appender>

   <root>
     <level value="debug" />
     <appender-ref ref="FILE" />
   </root>
</configuration>

With this configuration, the file would be rolled each time it reaches 5MB.

When I look at the configuration file that you sent, something seems strange to me:
Why do you configure two Loggers with the same Appender and one of them with the 
Additivity flag set to false? One would obtain the same result simply by attaching 
the RollingFileAppender to the root logger.

Hope this helps you get on track with logback. Do not hesitate to write again if you 
run into trouble.

Sébastien

-- 
Sébastien Pennec
sebastien at qos.ch

Logback: The reliable, generic, fast and flexible logging framework for Java.

Samuel Doyle a écrit :
> Hello,
> 
> I'm new to logback but read your documentation, I an not receiving any 
> output to my logfile. Here is my configuration file, following this is 
> the output from logback to the console. The only thing I notice is a 
> warning about a TriggerPolicy. If this is the case do you have example 
> syntax?
> ---
> 
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <configuration>
>  
>   <appender name="bitranlog" 
> class="ch.qos.logback.core.rolling.RollingFileAppender">
>     <param name="append" value="true"/>
>     <param name="MaxBackupIndex" value="1"/>
>     <param name="file" value="/tmp/bitran.log"/>
>     <param name="MaxFileSize" value="5MB"/>
>     <layout class="ch.qos.logback.classic.PatternLayout">
>       <param name="pattern" value="%d [%-15.15t] %-5p %-30.30c{1} - %m%n"/>
>     </layout>
>   </appender>
>    
>   <logger name="org.accma.concentrator.services.bitran.BiTranService" 
> additivity="false">
>     <level value="debug"/>
>     <appender-ref ref="bitranlog"/>
>   </logger>
>  
>   <root>
>     <level value="debug" />
>      <appender-ref ref="bitranlog" />
>   </root>
> 
> </configuration>
> 
> ---
> Here is console output when using LoggerStatusPrinter:
> ---
> 
> startElement [configuration]
> startElement [appender]
> startElement [param]
> startElement [param]
> LOGBACK: No context given for ch.qos.logback.core.util.PropertySetter at 8c5ea2
> startElement [param]
> startElement [param]
> LOGBACK: No context given for 
> ch.qos.logback.core.util.PropertySetter at 198defc
> startElement [layout]
> startElement [param]
> startElement [logger]
> startElement [level]
> startElement [appender-ref]
> startElement [root]
> startElement [level]
> startElement [appender-ref]
> INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - 
> Ignoring debug attribute.
> 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]
> 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 t
> he object stack
> INFO in ch.qos.logback.classic.joran.action.LevelAction - 
> org.accma.concentrator.services.bitran.Bi
> TranService level set to DEBUG
> INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching 
> appender named [bitranlog to
>  Logger[org.accma.concentrator.services.bitran.BiTranService]
> INFO in ch.qos.logback.classic.joran.action.LevelAction - root level set 
> to DEBUG
> INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching 
> appender named [bitranlog to
>  Logger[root]
> 
> 
> Thanks, S.D.
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user



More information about the Logback-user mailing list