|
||||||||||
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.QpidCompositeRollingAppender
public class QpidCompositeRollingAppender
CompositeRollingAppender combines RollingFileAppender and DailyRollingFileAppender
It can function as either
or do both at the same time (making size based rolling files like RollingFileAppender until a data/time boundary is
crossed at which time it rolls all of those files as per the DailyRollingFileAppender) based on the setting for
rollingStyle
.
To use CompositeRollingAppender to roll log files as they reach a certain size
(like RollingFileAppender), set rollingStyle=1 (@see config.size)
To use CompositeRollingAppender to roll log
files at certain time intervals (daily for example), set rollingStyle=2 and a datePattern (@see config.time)
To
have CompositeRollingAppender roll log files at a certain size AND rename those according to time intervals, set
rollingStyle=3 (@see config.composite)
A of few additional optional features have been added:
-- Attach date pattern for current log file (@see
staticLogFileName)
-- Backup number increments for newer files (@see countDirection)
-- Infinite number of
backups by file size (@see maxSizeRollBackups)
A few notes and warnings: For large or infinite number of
backups countDirection > 0 is highly recommended, with staticLogFileName = false if time based rolling is also used
-- this will reduce the number of file renamings to few or none. Changing staticLogFileName or countDirection
without clearing the directory could have nasty side effects. If Date/Time based rolling is enabled,
CompositeRollingAppender will attempt to roll existing files in the directory without a date/time tag based on the
last modified date of the base log files last modification.
A maximum number of backups based on
date/time boundries would be nice but is not yet implemented.
Field Summary | |
---|---|
protected String |
backupFilesToPath
Path provided in configuration. |
protected String |
baseFileName
FileName provided in configuration. |
(package private) static int |
BY_COMPOSITE
|
(package private) static int |
BY_DATE
|
(package private) static int |
BY_SIZE
Style of rolling to use |
protected boolean |
compress
Do we want to .gz our backup files. |
protected boolean |
compressAsync
Do we want to use a second thread when compressing our backup files. |
(package private) org.apache.log4j.QpidCompositeRollingAppender.Compressor |
compressor
|
protected int |
countDirection
By default newer files have lower numbers. |
protected int |
curSizeRollBackups
How many sized based backups have been made so far |
protected int |
curTimeRollBackups
|
(package private) Executor |
executor
|
(package private) static int |
HALF_DAY
|
protected long |
maxFileSize
The default maximum file size is 10MB. |
protected int |
maxSizeRollBackups
There is zero backup files by default. |
protected int |
maxTimeRollBackups
not yet implemented |
(package private) Date |
now
Holds date of last roll over |
(package private) org.apache.log4j.RollingCalendar |
rc
Helper class to determine next rollover time |
protected boolean |
rollDate
|
protected int |
rollingStyle
Style of rolling to Use. |
protected boolean |
rollSize
|
(package private) static String |
S_BY_COMPOSITE
|
(package private) static String |
S_BY_DATE
|
(package private) static String |
S_BY_SIZE
|
(package private) SimpleDateFormat |
sdf
|
protected boolean |
staticLogFileName
By default file.log is always the current file. |
(package private) static int |
TOP_OF_DAY
|
(package private) static int |
TOP_OF_HOUR
|
(package private) static int |
TOP_OF_MINUTE
|
(package private) static int |
TOP_OF_MONTH
|
(package private) static int |
TOP_OF_TROUBLE
|
(package private) static int |
TOP_OF_WEEK
|
protected boolean |
zeroBased
Do we want to start numbering files at zero. |
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 | |
---|---|
QpidCompositeRollingAppender()
The default constructor does nothing. |
|
QpidCompositeRollingAppender(org.apache.log4j.Layout layout,
String filename)
Instantiate a CompositeRollingAppender and open the file designated by filename . |
|
QpidCompositeRollingAppender(org.apache.log4j.Layout layout,
String filename,
boolean append)
Instantiate a CompositeRollingAppender and open the file designated by filename . |
|
QpidCompositeRollingAppender(org.apache.log4j.Layout layout,
String filename,
String datePattern)
Instantiate a CompositeRollingAppender and open the file designated by filename . |
|
QpidCompositeRollingAppender(org.apache.log4j.Layout layout,
String filename,
String datePattern,
boolean append)
Instantiate a CompositeRollingAppender and open the file designated by filename . |
Method Summary | |
---|---|
void |
activateOptions()
Sets initial conditions including date/time roll over information, first check, scheduledFilename, and calls existingInit to initialize the current # of backups. |
(package private) int |
computeCheckPeriod()
|
protected void |
deleteFile(String relativeFileName)
Delete the given file that is prepended with the relative path to the log directory. |
protected void |
doCompress(File from,
File to)
|
protected void |
existingInit()
Initializes based on exisiting conditions at time of activateOptions . |
String |
getBackupFilesToPath()
|
boolean |
getCompressAsync()
|
boolean |
getCompressBackupFiles()
|
int |
getCountDirection()
|
String |
getDatePattern()
Returns the value of the DatePattern option. |
long |
getMaximumFileSize()
Get the maximum size that the output file is allowed to reach before being rolled over to backup files. |
int |
getMaxSizeRollBackups()
Returns the value of the maxSizeRollBackups option. |
int |
getRollingStyle()
|
boolean |
getStaticLogFileName()
|
boolean |
getZeroBased()
|
protected void |
rollFile(String from,
String to,
boolean compress)
Renames file from to file to . |
protected void |
rollOverSize()
Implements roll overs base on file size. |
protected void |
rollOverTime()
Rollover the file(s) to date/time tagged file(s). |
void |
setbackupFilesToPath(String path)
|
void |
setCompressAsync(boolean c)
|
void |
setCompressBackupFiles(boolean c)
|
void |
setCountDirection(int direction)
|
void |
setDatePattern(String pattern)
The DatePattern takes a string in the same format as expected by SimpleDateFormat . |
void |
setFile(String file)
|
void |
setFile(String fileName,
boolean append)
Creates and opens the file for logging. |
void |
setMaxFileSize(long maxFileSize)
Set the maximum size that the output file is allowed to reach before being rolled over to backup files. |
void |
setMaxFileSize(String value)
Set the maximum size that the output file is allowed to reach before being rolled over to backup files. |
void |
setMaximumFileSize(long maxFileSize)
Set the maximum size that the output file is allowed to reach before being rolled over to backup files. |
void |
setMaxSizeRollBackups(int maxBackups)
Set the maximum number of backup files to keep around based on file size. |
protected void |
setQWForFiles(Writer writer)
|
void |
setRollingStyle(int style)
|
void |
setStaticLogFileName(boolean s)
|
void |
setStaticLogFileName(String value)
|
void |
setZeroBased(boolean z)
|
protected void |
subAppend(org.apache.log4j.spi.LoggingEvent event)
Handles append time behavior for CompositeRollingAppender. |
Methods inherited from class org.apache.log4j.FileAppender |
---|
closeFile, getAppend, getBufferedIO, getBufferSize, getFile, reset, setAppend, setBufferedIO, setBufferSize, setFile |
Methods inherited from class org.apache.log4j.WriterAppender |
---|
append, checkEntryConditions, close, closeWriter, createWriter, 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 |
Field Detail |
---|
static final int TOP_OF_TROUBLE
static final int TOP_OF_MINUTE
static final int TOP_OF_HOUR
static final int HALF_DAY
static final int TOP_OF_DAY
static final int TOP_OF_WEEK
static final int TOP_OF_MONTH
static final int BY_SIZE
static final int BY_DATE
static final int BY_COMPOSITE
static final String S_BY_SIZE
static final String S_BY_DATE
static final String S_BY_COMPOSITE
Date now
SimpleDateFormat sdf
org.apache.log4j.RollingCalendar rc
protected long maxFileSize
protected int maxSizeRollBackups
protected int curSizeRollBackups
protected int maxTimeRollBackups
protected int curTimeRollBackups
protected int countDirection
protected int rollingStyle
protected boolean rollDate
protected boolean rollSize
protected boolean staticLogFileName
protected String baseFileName
protected boolean compress
protected boolean compressAsync
protected boolean zeroBased
protected String backupFilesToPath
org.apache.log4j.QpidCompositeRollingAppender.Compressor compressor
Executor executor
Constructor Detail |
---|
public QpidCompositeRollingAppender()
public QpidCompositeRollingAppender(org.apache.log4j.Layout layout, String filename, String datePattern) throws IOException
CompositeRollingAppender
and open the file designated by filename
. The
opened filename will become the ouput destination for this appender.
IOException
public QpidCompositeRollingAppender(org.apache.log4j.Layout layout, String filename, boolean append) throws IOException
filename
. The opened filename
will become the ouput destination for this appender.
If the append
parameter is true, the file will be appended to. Otherwise, the file desginated by
filename
will be truncated before being opened.
IOException
public QpidCompositeRollingAppender(org.apache.log4j.Layout layout, String filename, String datePattern, boolean append) throws IOException
filename
. The opened filename
will become the ouput destination for this appender.
IOException
public QpidCompositeRollingAppender(org.apache.log4j.Layout layout, String filename) throws IOException
filename
. The opened filename
will become the output destination for this appender.
The file will be appended to. DatePattern is default.
IOException
Method Detail |
---|
public void setDatePattern(String pattern)
SimpleDateFormat
. This
options determines the rollover schedule.
public String getDatePattern()
public int getMaxSizeRollBackups()
public long getMaximumFileSize()
public void setMaxSizeRollBackups(int maxBackups)
Set the maximum number of backup files to keep around based on file size.
The MaxSizeRollBackups option determines how many backup files are kept before the oldest is erased.
This option takes an integer value. If set to zero, then there will be no backup files and the log file will be
truncated when it reaches MaxFileSize
. If a negative number is supplied then no deletions will be
made. Note that this could result in very slow performance as a large number of files are rolled over unless
setCountDirection(int)
up is used.
The maximum applys to -each- time based group of files and -not- the total. Using a daily roll the maximum total files would be (#days run) * (maxSizeRollBackups)
public void setMaxFileSize(long maxFileSize)
This method is equivalent to setMaxFileSize(long)
except that it is required for differentiating the setter
taking a long
argument from the setter taking a String
argument by the JavaBeans Introspector
.
setMaxFileSize(String)
public void setMaximumFileSize(long maxFileSize)
This method is equivalent to setMaxFileSize(long)
except that it is required for differentiating the setter
taking a long
argument from the setter taking a String
argument by the JavaBeans Introspector
.
setMaxFileSize(String)
public void setMaxFileSize(String value)
In configuration files, the MaxFileSize option takes an long integer in the range 0 - 2^63. You can specify the value with the suffixes "KB", "MB" or "GB" so that the integer is interpreted being expressed respectively in kilobytes, megabytes or gigabytes. For example, the value "10KB" will be interpreted as 10240.
protected void setQWForFiles(Writer writer)
setQWForFiles
in class org.apache.log4j.FileAppender
int computeCheckPeriod()
protected void subAppend(org.apache.log4j.spi.LoggingEvent event)
subAppend
in class org.apache.log4j.WriterAppender
public void setFile(String file)
setFile
in class org.apache.log4j.FileAppender
public void setFile(String fileName, boolean append) throws IOException
staticLogFileName
is false then the fully qualified name
is determined and used.
IOException
public int getCountDirection()
public void setCountDirection(int direction)
public int getRollingStyle()
public void setRollingStyle(int style)
public boolean getStaticLogFileName()
public void setStaticLogFileName(boolean s)
public void setStaticLogFileName(String value)
public boolean getCompressBackupFiles()
public void setCompressBackupFiles(boolean c)
public boolean getCompressAsync()
public void setCompressAsync(boolean c)
public boolean getZeroBased()
public void setZeroBased(boolean z)
public String getBackupFilesToPath()
public void setbackupFilesToPath(String path)
protected void existingInit()
activateOptions
. The following is done:
public void activateOptions()
existingInit
to initialize the current # of backups.
activateOptions
in interface org.apache.log4j.spi.OptionHandler
activateOptions
in class org.apache.log4j.FileAppender
protected void rollOverTime()
protected void rollFile(String from, String to, boolean compress)
from
to file to
. It also checks for existence of target file and deletes
if it does.
protected void deleteFile(String relativeFileName)
protected void rollOverSize()
If the maximum number of size based backups is reached (curSizeRollBackups == maxSizeRollBackups
If
countDirection
< 0, then files {File.1
, ..., File.curSizeRollBackups -1
}
are renamed to {File.2
, ..., File.curSizeRollBackups
}. Moreover, File
is
renamed File.1
and closed.
A new file is created to receive further log output.
If maxSizeRollBackups
is equal to zero, then the File
is truncated with no backup
files created.
If maxSizeRollBackups
< 0, then File
is renamed if needed and no files are deleted.
protected void doCompress(File from, File to)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |