|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.util.logging.AbstractLogWriter<String>
com.antelmann.util.logging.LogFile
public class LogFile
LogFile provides great convenience for logging information from a program into a file. By default, every call to a write method is flushed immediately, so the content of a LogFile always accurately corresponds to how far a logging program actually ran; i.e. the logging as a LogWriter is done synchronously. The object holds a write-lock on the file it writes to (through a java.io.FileWriter). IOExceptions are replaced with LogException, which should make it easier to write the code for the logging program - with the usual drawbacks of ensuring proper Exception handling. For most cases, however, this should make things easier.
FileLog,
LogException,
Logger,
LogEntry,
DBLineLogFormatter| Field Summary |
|---|
| Fields inherited from class com.antelmann.util.logging.AbstractLogWriter |
|---|
filter |
| Fields inherited from interface com.antelmann.util.Filter |
|---|
EXCLUDE_ALL_FILTER, INCLUDE_ALL_FILTER |
| Constructor Summary | |
|---|---|
LogFile(File file)
uses the simple format |
|
LogFile(File file,
boolean useSimpleFormat)
|
|
LogFile(File file,
LogEntryFormatter<String> formatter)
|
|
LogFile(File file,
LogEntryFormatter<String> formatter,
boolean autoFlush,
boolean useDailyPattern)
constructs a LogFile based on the given file and formatter. |
|
LogFile(String fileName)
This constructor simply calls LogFile(new File(fileName)) |
|
| Method Summary | |
|---|---|
void |
close()
closes the underlying writer. |
long |
elapsedTime()
returns the elapsed time since LogFile initialization or since the last call to resetTime(). |
protected void |
finalize()
|
void |
flush()
only needed if getAlwaysFlush() returns false |
boolean |
getAlwaysFlush()
true by default |
File |
getFile()
|
LogEntryFormatter<String> |
getLogFormatter()
|
boolean |
isLogAtClose()
|
void |
reInitialize(File file,
LogEntryFormatter<String> formatter,
boolean autoFlush,
boolean useDailyPattern)
This method initializes the LogFile to a new file. |
void |
resetTime()
resets the time of the embedded Stopwatch that gets initialized with the constructor |
void |
setAlwaysFlush(boolean flag)
|
void |
setLogAtClose(boolean logAtClose)
|
void |
setLogFormatter(LogEntryFormatter<String> formatter)
formatter must not be null |
String |
toString()
|
boolean |
usesDailyPattern()
|
protected void |
write(String text)
This is the only method actually writing to the file; all other 'write*' methods call this method |
void |
writeElapsedTime()
writes a LogFile entry with the elapsed time since initialization or since the last call to resetTime(). |
void |
writeln()
|
void |
writeln(Object o)
note that this function doesn't write serialized objects, but it calls toString() on the object and writes the String to the file |
void |
writeln(String text)
|
void |
writeLogPattern(String pattern)
This method writes a one-line version String of the entry into the file. |
| Methods inherited from class com.antelmann.util.logging.AbstractLogWriter |
|---|
accept, getLogFilter, setLogFilter, write |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public LogFile(String fileName)
throws IOException
LogFile(new File(fileName))
IOException
public LogFile(File file)
throws IOException
IOException
public LogFile(File file,
boolean useSimpleFormat)
throws IOException
useSimpleFormat - if true, a StringLineFormatter is used; otherwise it's a DBLineLogFormatter
IOException
public LogFile(File file,
LogEntryFormatter<String> formatter)
throws IOException
IOException
public LogFile(File file,
LogEntryFormatter<String> formatter,
boolean autoFlush,
boolean useDailyPattern)
throws IOException
IOException| Method Detail |
|---|
public void reInitialize(File file,
LogEntryFormatter<String> formatter,
boolean autoFlush,
boolean useDailyPattern)
throws IOException
IOExceptionpublic boolean usesDailyPattern()
public void resetTime()
Stopwatchpublic long elapsedTime()
public void writeLogPattern(String pattern)
throws LogException
writeLogPattern in class AbstractLogWriter<String>LogExceptionDBLineLogFormatterpublic LogEntryFormatter<String> getLogFormatter()
getLogFormatter in class AbstractLogWriter<String>public void setLogFormatter(LogEntryFormatter<String> formatter)
AbstractLogWriter
setLogFormatter in class AbstractLogWriter<String>
public void writeElapsedTime()
throws LogException
LogException
public void writeln()
throws IOException
IOException
public void writeln(String text)
throws IOException
IOException
protected void write(String text)
throws IOException
IOException
public void flush()
throws IOException
getAlwaysFlush() returns false
IOExceptionpublic void setAlwaysFlush(boolean flag)
public boolean getAlwaysFlush()
public void writeln(Object o)
throws IOException
IOException
public void close()
throws IOException
close in interface CloseableIOExceptionpublic boolean isLogAtClose()
public void setLogAtClose(boolean logAtClose)
public File getFile()
public String toString()
toString in class Object
protected void finalize()
throws Exception
finalize in class ObjectException
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||