it.openutils.log4j
Class EnhancedDailyRollingFileAppender

java.lang.Object
  extended by org.apache.log4j.AppenderSkeleton
      extended by org.apache.log4j.WriterAppender
          extended by org.apache.log4j.FileAppender
              extended by it.openutils.log4j.EnhancedDailyRollingFileAppender
All Implemented Interfaces:
org.apache.log4j.Appender, org.apache.log4j.spi.OptionHandler

public class EnhancedDailyRollingFileAppender
extends org.apache.log4j.FileAppender

Enhanced version of standard DailyRollingFileAppender that allow moving rotated files to a different directory. You can configure the target directory by setting the archiveDirectory property. The default value is archive Note that since DailyRollingFileAppender is not easily extendible, this class is actually a copy and paste of all the code with slights modifications...

Version:
$Id: EnhancedDailyRollingFileAppender.java 925 2008-11-10 15:26:41Z fgiust $
Author:
fgiust

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
EnhancedDailyRollingFileAppender()
          The default constructor does nothing.
EnhancedDailyRollingFileAppender(org.apache.log4j.Layout layout, java.lang.String filename, java.lang.String datePattern)
          Instantiate a DailyRollingFileAppender and open the file designated by filename.
 
Method Summary
 void activateOptions()
           
 java.lang.String getDatePattern()
          Returns the value of the DatePattern option.
 void setArchiveDirectory(java.lang.String archiveDirectory)
          Sets the archiveDirectory.
 void setDatePattern(java.lang.String pattern)
          The DatePattern takes a string in the same format as expected by SimpleDateFormat.
protected  void subAppend(org.apache.log4j.spi.LoggingEvent event)
          This method differentiates DailyRollingFileAppender from its super class.
 
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, close, closeWriter, createWriter, getEncoding, getImmediateFlush, requiresLayout, setEncoding, setErrorHandler, setImmediateFlush, setWriter, 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

EnhancedDailyRollingFileAppender

public EnhancedDailyRollingFileAppender()
The default constructor does nothing.


EnhancedDailyRollingFileAppender

public EnhancedDailyRollingFileAppender(org.apache.log4j.Layout layout,
                                        java.lang.String filename,
                                        java.lang.String datePattern)
                                 throws java.io.IOException
Instantiate a DailyRollingFileAppender and open the file designated by filename. The opened filename will become the ouput destination for this appender.

Throws:
java.io.IOException
Method Detail

setArchiveDirectory

public void setArchiveDirectory(java.lang.String archiveDirectory)
Sets the archiveDirectory.

Parameters:
archiveDirectory - the archiveDirectory to set

setDatePattern

public void setDatePattern(java.lang.String pattern)
The DatePattern takes a string in the same format as expected by SimpleDateFormat. This options determines the rollover schedule.


getDatePattern

public java.lang.String getDatePattern()
Returns the value of the DatePattern option.


activateOptions

public void activateOptions()
Specified by:
activateOptions in interface org.apache.log4j.spi.OptionHandler
Overrides:
activateOptions in class org.apache.log4j.FileAppender

subAppend

protected void subAppend(org.apache.log4j.spi.LoggingEvent event)
This method differentiates DailyRollingFileAppender from its super class.

Before actually logging, this method will check whether it is time to do a rollover. If it is, it will schedule the next rollover time and then rollover.

Overrides:
subAppend in class org.apache.log4j.WriterAppender


Copyright © 2009 Openmind. All Rights Reserved.