Log4j 1.3alpha-5

org.apache.log4j.rolling
Class RollingFileAppender

java.lang.Object
  |
  +--org.apache.log4j.spi.ComponentBase
        |
        +--org.apache.log4j.AppenderSkeleton
              |
              +--org.apache.log4j.WriterAppender
                    |
                    +--org.apache.log4j.FileAppender
                          |
                          +--org.apache.log4j.rolling.RollingFileAppender
All Implemented Interfaces:
Appender, Component, OptionHandler

public class RollingFileAppender
extends FileAppender

RollingFileAppender extends FileAppender to backup the log files depending on RollingPolicy and TriggeringPolicy.

To be of any use, a RollingFileAppender instance must have both a RollingPolicy and a TriggeringPolicy set up. However, if its RollingPolicy also implements the TriggeringPolicy interface, then only the former needs to be set up. For example, TimeBasedRollingPolicy acts both as a RollingPolicy and a TriggeringPolicy.

RollingFileAppender can be configured programattically or using JoranConfigurator. Here is a sample configration file:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration>

<log4j:configuration debug="true">

  <appender name="ROLL" class="org.apache.log4j.rolling.RollingFileAppender">
    <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
      <param name="FileNamePattern" value="/wombat/foo.%d{yyyy-MM}.gz"/>
    </rollingPolicy>

    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%c{1} - %m%n"/>
    </layout>     
  </appender>

  <root">
    <appender-ref ref="ROLL"/>
  </root>
 
</log4j:configuration>

This configuration file specifies a monthly rollover schedule including automatic compression of the archived files. See TimeBasedRollingPolicy for more details.

Since:
1.3
Author:
Heinz Richter, Ceki Gülcü

Field Summary
 
Fields inherited from class org.apache.log4j.FileAppender
bufferedIO, bufferSize, fileAppend, fileName
 
Fields inherited from class org.apache.log4j.WriterAppender
encoding, immediateFlush, inOrder, writer
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, headFilter, layout, name, tailFilter, threshold
 
Fields inherited from class org.apache.log4j.spi.ComponentBase
repository
 
Constructor Summary
RollingFileAppender()
          The default constructor simply calls its parents constructor.
 
Method Summary
 void activateOptions()
          If the value of File is not null, then FileAppender.setFile(java.lang.String) is called with the values of File and Append properties.
 RollingPolicy getRollingPolicy()
           
 TriggeringPolicy getTriggeringPolicy()
           
 void rollover()
          Implements the usual roll over behaviour.
 void setRollingPolicy(RollingPolicy policy)
          Sets the rolling policy.
 void setTriggeringPolicy(TriggeringPolicy policy)
           
protected  void subAppend(LoggingEvent event)
          This method differentiates RollingFileAppender from its super class.
 
Methods inherited from class org.apache.log4j.FileAppender
closeFile, getAppend, getBufferedIO, getBufferSize, getFile, setAppend, setBufferedIO, setBufferSize, setFile, setFile
 
Methods inherited from class org.apache.log4j.WriterAppender
append, checkEntryConditions, close, closeWriter, createWriter, getEncoding, getImmediateFlush, requiresLayout, setEncoding, setImmediateFlush, setWriter, writeFooter, writeHeader, xreset
 
Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setLayout, setName, setThreshold
 
Methods inherited from class org.apache.log4j.spi.ComponentBase
getLogger, setLoggerRepository
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.log4j.Appender
setLoggerRepository
 

Constructor Detail

RollingFileAppender

public RollingFileAppender()
The default constructor simply calls its parents constructor.

Method Detail

activateOptions

public void activateOptions()
Description copied from class: FileAppender
If the value of File is not null, then FileAppender.setFile(java.lang.String) is called with the values of File and Append properties.

Specified by:
activateOptions in interface OptionHandler
Overrides:
activateOptions in class FileAppender

rollover

public void rollover()
Implements the usual roll over behaviour.

If MaxBackupIndex is positive, then files {File.1, ..., File.MaxBackupIndex -1} are renamed to {File.2, ..., File.MaxBackupIndex}. Moreover, File is renamed File.1 and closed. A new File is created to receive further log output.

If MaxBackupIndex is equal to zero, then the File is truncated with no backup files created.


subAppend

protected void subAppend(LoggingEvent event)
This method differentiates RollingFileAppender from its super class.

Overrides:
subAppend in class WriterAppender

getRollingPolicy

public RollingPolicy getRollingPolicy()

getTriggeringPolicy

public TriggeringPolicy getTriggeringPolicy()

setRollingPolicy

public void setRollingPolicy(RollingPolicy policy)
Sets the rolling policy. In case the 'policy' argument also implements TriggeringPolicy, then the triggering policy for this appender is automatically set to be the policy argument.

Parameters:
policy -

setTriggeringPolicy

public void setTriggeringPolicy(TriggeringPolicy policy)

Log4j 1.3alpha-5

Copyright 2000-2005 Apache Software Foundation.