public abstract class FileLogger<T> extends java.util.TimerTask implements ShutdownHandler
| 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,
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() |
void |
setDatePattern(java.lang.String datePattern) |
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 |
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,
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 setDatePattern(java.lang.String datePattern)
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 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.Runnablerun in class java.util.TimerTaskpublic void shutdown()
shutdown in interface ShutdownHandler