|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.abstracthorizon.danube.support.logging.util.LogFileRotatorImpl
public class LogFileRotatorImpl
Simple implementation of LogFileRotator interface. This implementation
knows how to keep certain number of generations of log files,
to rotate logs when size exceeds or age of file (age is calculated since file
is created by an instance of this class) or at one predefined moment during the day.
Each time this class is instantiated log rotation is enforced. That is done
in the lazy manner - first call to logFile() method will do so.
| Field Summary | |
|---|---|
protected OutputStream |
cachedOutputStream
Cached output stream |
protected long |
lastAccessed
When is this object lass accessed through logFile() method. |
protected File |
logFile
Log file |
protected long |
logFileCreated
When is log file created |
protected org.slf4j.Logger |
logger
Logger |
protected File |
logPath
Log file path |
protected long |
nextRotate
When is scheduled next rotation based on the time of the day or 0 if none |
| Constructor Summary | |
|---|---|
LogFileRotatorImpl()
Constructor |
|
LogFileRotatorImpl(File logFile)
Constructor |
|
| Method Summary | |
|---|---|
protected void |
check()
Checks if file needs to be rotated |
protected File |
createFileName(int g)
Creates a file name from given generation number. |
protected void |
createLogFile()
Creates log file |
int |
getBufferLen()
Returns file buffer len |
int |
getCheckDelayMillis()
Returns check delay in milliseconds |
File |
getLogDirectory()
Returns the direcotry of log file. |
File |
getLogFile()
Returns file handle of the log file. |
String |
getLogFileName()
Returns last part of log file's path |
long |
getMaxAge()
Returns maximum age of the file. |
long |
getMaxSize()
Returns maximum size of the file. |
int |
getNumberOfGenerations()
Returns defined number of generations |
Calendar |
getTimeOfDay()
Returns time of day when rotation is going to happen. |
OutputStream |
logFile()
This method first checks if we have accessed it too quickly since last time according to the checkDelayMillis field. |
void |
rotate()
Rotates the log files |
void |
setBufferLen(int bufferLen)
Sets file buffer len |
void |
setCheckDelayMillis(int checkDelayMillis)
Sets check delay in milliseconds |
void |
setLogDirectory(File logPath)
Sets log directory. |
void |
setLogFile(File logFile)
Sets file handle of the log file |
void |
setLogFileName(String name)
Sets last part of a path of log file. |
void |
setMaxAge(long maxAge)
Sets maximum age of the file |
void |
setMaxSize(long maxSize)
Sets maximum size of the file |
void |
setNumberOfGenerations(int numberOfGeneration)
Sets defined number of generations |
void |
setTimeOfDay(Calendar timeOfDay)
Sets time of day when rotation is going to happen |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final org.slf4j.Logger logger
protected OutputStream cachedOutputStream
protected File logFile
protected File logPath
protected long lastAccessed
logFile() method.
protected long nextRotate
protected long logFileCreated
| Constructor Detail |
|---|
public LogFileRotatorImpl()
public LogFileRotatorImpl(File logFile)
logFile - log file handle| Method Detail |
|---|
public OutputStream logFile()
throws IOException
checkDelayMillis field. If so
check should log be rotated or not wont be done.
logFile in interface LogFileRotatorIOException - io exceptionpublic File getLogFile()
public void setLogFile(File logFile)
logFile - file handle of the log filepublic File getLogDirectory()
setLogDirectory(File)public void setLogDirectory(File logPath)
setLogFileName(String) instead
of setLogFile(File). There is no
need using these two (this and setLogFileName(String) in
log file is set through setLogFile(File).
Settin only log directory will assume log file name
as "access.log". If you want
to set log directory and use different name use setLogFileName(String) to
set the name after you have
set the directory using this method
logPath - log file directorypublic String getLogFileName()
public void setLogFileName(String name)
setLogDirectory(File) for more explanations.
name - public long getMaxAge()
maxAgepublic void setMaxAge(long maxAge)
maxAge - maximum age of the filemaxAgepublic long getMaxSize()
maxSizepublic void setMaxSize(long maxSize)
maxAge - maximum size of the filemaxSizepublic int getNumberOfGenerations()
numberOfGenerationspublic void setNumberOfGenerations(int numberOfGeneration)
numberOfGeneration - defined number of generationsnumberOfGenerationspublic Calendar getTimeOfDay()
timeOfDaypublic void setTimeOfDay(Calendar timeOfDay)
timeOfDay - time of day when rotation is going to happentimeOfDaypublic int getCheckDelayMillis()
checkDelayMillispublic void setCheckDelayMillis(int checkDelayMillis)
checkDelayMillis - check delay in millisecondscheckDelayMillispublic int getBufferLen()
bufferLenpublic void setBufferLen(int bufferLen)
bufferLen - file buffer lenbufferLen
protected void check()
throws IOException
IOException - io exception
public void rotate()
throws IOException
rotate in interface LogFileRotatorIOException - io exceptionprotected File createFileName(int g)
logFile i sreturned
g - generation number
protected void createLogFile()
throws IOException
IOException - io exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||