public abstract class FileLogger<T> extends ReschedulableTimerTask implements ShutdownHandler
Modifier and Type | Class and Description |
---|---|
static interface |
FileLogger.RolloverHandler<T>
Define a handler to be called when the logger rolls over to a new file.
|
Modifier | Constructor and Description |
---|---|
protected |
FileLogger(java.lang.String prefix,
java.lang.String datePattern,
java.lang.String suffix,
int flushEveryNSeconds)
Create a FileLogger using the specified file prefix, date pattern, suffix, and flush interval,
storing the log files in YAAC's default log directory.
|
protected |
FileLogger(java.lang.String prefix,
java.lang.String datePattern,
java.lang.String suffix,
int flushEveryNSeconds,
long rolloverInterval)
Create a FileLogger using the specified file prefix, date pattern, suffix, and flush interval,
storing the log files in YAAC's default log directory.
|
protected |
FileLogger(java.lang.String prefix,
java.lang.String datePattern,
java.lang.String suffix,
int flushEveryNSeconds,
java.lang.String logDirPath)
Create a FileLogger using the specified file prefix, date pattern, suffix, and flush interval,
storing the log files in the explicitly specified log directory.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
dumpRecordQueueToFile(java.io.File logFileFile,
java.util.ArrayList<T> recordQueue)
Subclasses should implement this method to open the specified sequential
file for append, then write each of the records in the recordQueue in order
to the file, then close the file.
|
void |
flush()
Dump the current contents of the backlog queue to the current log file.
|
static java.io.File |
getDefaultLogDir()
Get the current default directory used for log files.
|
void |
log(T record)
Append one record to the log file, using asynchronous background writing.
|
void |
log(T record,
java.util.Date date)
Append one record to the log file, using asynchronous background writing.
|
void |
log(T record,
long date)
Append one record to the log file, using asynchronous background writing.
|
void |
run()
DO NOT CALL.
|
void |
setDatePattern(java.lang.String datePattern)
Set the pattern for formatting the date stamp in the log file name.
|
static void |
setDefaultLogDir(java.lang.String defaultLogDirPath)
Specify the default directory where all log files will be kept.
|
void |
setFilePrefix(java.lang.String prefix)
Change the constant prefix that should be used before the date part of the log file name.
|
void |
setFileSuffix(java.lang.String suffix)
Change the constant suffix that should be used after the date part of the log file name.
|
void |
setFlushInterval(int flushEveryNSeconds)
Set how frequently the logger should dump its backlog queue to disk and close the file
for checkpointing.
|
void |
setLogDirectory(java.lang.String logDirPath)
Set the directory in which log files should be created.
|
void |
setRolloverHandler(FileLogger.RolloverHandler<T> rolloverHandler)
Set (or clear) the handler to be informed whenever the FileLogger advances to a new periodic log file.
|
void |
setRolloverInterval(long rolloverInterval)
Set the interval between closing of one log file and opening of the next.
|
void |
setTimeZone(java.util.TimeZone tz)
Set the time zone for use in calculating file rollovers.
|
void |
shutdown()
Do whatever cleanup this object needs for program shutdown.
|
protected FileLogger(java.lang.String prefix, java.lang.String datePattern, java.lang.String suffix, int flushEveryNSeconds)
prefix
- String file name prefix (before the date)datePattern
- format string for file name embedded date, using SimpleDateFormat directivessuffix
- String file name suffix (after the date)flushEveryNSeconds
- the interval between log flushes in secondssetDefaultLogDir(String)
protected FileLogger(java.lang.String prefix, java.lang.String datePattern, java.lang.String suffix, int flushEveryNSeconds, long rolloverInterval)
prefix
- String file name prefix (before the date)datePattern
- format string for file name embedded date, using SimpleDateFormat directivessuffix
- String file name suffix (after the date)flushEveryNSeconds
- the interval between log flushes in secondsrolloverInterval
- the interval in milliseconds between log file changessetDefaultLogDir(String)
protected FileLogger(java.lang.String prefix, java.lang.String datePattern, java.lang.String suffix, int flushEveryNSeconds, java.lang.String logDirPath)
prefix
- String file name prefix (before the date)datePattern
- format string for file name embedded date, using SimpleDateFormat directivessuffix
- String file name suffix (after the date)flushEveryNSeconds
- the interval between log flushes in secondslogDirPath
- String path name of directory to contain the log filespublic void setLogDirectory(java.lang.String logDirPath)
logDirPath
- String pathname of log-containing directorypublic static void setDefaultLogDir(java.lang.String defaultLogDirPath)
defaultLogDirPath
- String absolute path to a directorypublic static java.io.File getDefaultLogDir()
public void setFlushInterval(int flushEveryNSeconds)
flushEveryNSeconds
- the interval in seconds between file closespublic void setTimeZone(java.util.TimeZone tz)
tz
- TimeZone to use for calculating rolloverspublic void setRolloverInterval(long rolloverInterval)
rolloverInterval
- time span for each log file instance in millisecondspublic void setDatePattern(java.lang.String datePattern)
datePattern
- String pattern for generating the date stamp in the file namesetRolloverInterval(long)
public void setFilePrefix(java.lang.String prefix)
prefix
- String name prefixpublic void setFileSuffix(java.lang.String suffix)
suffix
- String name suffixpublic void log(T record)
record
- data record to log of the specified generic typepublic void log(T record, java.util.Date date)
record
- data record to log of the specified generic typedate
- Date when record was created, received, etc.public void log(T record, long date)
record
- data record to log of the specified generic typedate
- long timestamp in milliseconds since midnight Jan 19 1970 UTC when record was created, received, etc.public void flush()
public void setRolloverHandler(FileLogger.RolloverHandler<T> rolloverHandler)
rolloverHandler
- RolloverHandler instance to be informed of rollovers, or null to no longer be informedpublic abstract void dumpRecordQueueToFile(java.io.File logFileFile, java.util.ArrayList<T> recordQueue) throws java.io.IOException
logFileFile
- File identifying the log file to open and writerecordQueue
- the ArrayList of ordered records to writejava.io.IOException
- if record saving fails for any reasonpublic final void run()
run
in interface java.lang.Runnable
public void shutdown()
shutdown
in interface ShutdownHandler