|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.log4j.AppenderSkeleton
org.apache.log4j.WriterAppender
org.apache.log4j.FileAppender
org.apache.log4j.rolling.RollingFileAppender
public final class RollingFileAppender
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 DOMConfigurator or
DOMConfigurator in log4j 1.2.15 or later. 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.
| Field Summary |
|---|
| Fields inherited from class org.apache.log4j.FileAppender |
|---|
bufferedIO, bufferSize, fileAppend, fileName |
| Fields inherited from class org.apache.log4j.WriterAppender |
|---|
encoding, immediateFlush, qw |
| Fields inherited from class org.apache.log4j.AppenderSkeleton |
|---|
closed, errorHandler, headFilter, layout, name, tailFilter, threshold |
| Constructor Summary | |
|---|---|
RollingFileAppender()
Construct a new instance. |
|
| Method Summary | |
|---|---|
void |
activateOptions()
Prepare instance of use. |
void |
close()
Close appender. |
protected java.io.OutputStreamWriter |
createWriter(java.io.OutputStream os)
Returns an OutputStreamWriter when passed an OutputStream. |
long |
getFileLength()
Get byte length of current active log file. |
RollingPolicy |
getRollingPolicy()
Get rolling policy. |
TriggeringPolicy |
getTriggeringPolicy()
Get triggering policy. |
void |
incrementFileLength(int increment)
Increments estimated byte length of current active log file. |
boolean |
parseUnrecognizedElement(org.w3c.dom.Element element,
java.util.Properties props)
Called to inform a configured object when an unrecognized child element is encountered. |
boolean |
rollover()
Implements the usual roll over behaviour. |
void |
setRollingPolicy(RollingPolicy policy)
Sets the rolling policy. |
void |
setTriggeringPolicy(TriggeringPolicy policy)
Set triggering policy. |
protected void |
subAppend(org.apache.log4j.spi.LoggingEvent event)
|
| Methods inherited from class org.apache.log4j.FileAppender |
|---|
closeFile, getAppend, getBufferedIO, getBufferSize, getFile, reset, setAppend, setBufferedIO, setBufferSize, setFile, setFile, setQWForFiles |
| Methods inherited from class org.apache.log4j.WriterAppender |
|---|
append, checkEntryConditions, closeWriter, getEncoding, getImmediateFlush, requiresLayout, setEncoding, setErrorHandler, setImmediateFlush, setWriter, shouldFlush, writeFooter, writeHeader |
| Methods inherited from class org.apache.log4j.AppenderSkeleton |
|---|
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setLayout, setName, setThreshold |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public RollingFileAppender()
| Method Detail |
|---|
public void activateOptions()
activateOptions in interface org.apache.log4j.spi.OptionHandleractivateOptions in class org.apache.log4j.FileAppenderpublic boolean rollover()
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.
protected void subAppend(org.apache.log4j.spi.LoggingEvent event)
subAppend in class org.apache.log4j.WriterAppenderpublic RollingPolicy getRollingPolicy()
public TriggeringPolicy getTriggeringPolicy()
public void setRollingPolicy(RollingPolicy policy)
policy - rolling policy.public void setTriggeringPolicy(TriggeringPolicy policy)
policy - triggering policy.public void close()
close in interface org.apache.log4j.Appenderclose in class org.apache.log4j.WriterAppenderprotected java.io.OutputStreamWriter createWriter(java.io.OutputStream os)
encoding property. If the encoding value is
specified incorrectly the writer will be opened using the default
system encoding (an error message will be printed to the loglog.
createWriter in class org.apache.log4j.WriterAppenderos - output stream, may not be null.
public long getFileLength()
public void incrementFileLength(int increment)
increment - additional bytes written to log file.
public boolean parseUnrecognizedElement(org.w3c.dom.Element element,
java.util.Properties props)
throws java.lang.Exception
parseUnrecognizedElement in interface UnrecognizedElementHandlerelement - element, may not be null.props - properties in force, may be null.
java.lang.Exception - throw an exception to prevent activation
of the configured object.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Copyright © 2010 The Apache Software Foundation. Licensed under the Apache License, Version 2.0
Apache Extras Companion for Apache log4j, Apache log4j and Apache are trademarks of the Apache Software Foundation.