|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsnaq.util.logging.LogUtil
public class LogUtil
Class providing simple logging and debug functionality, which can be easily instantiated and used as a logging object. This class is not related to other external logging libraries, and is used to provide a standalone solution for writing basic log files.
Constructor Summary | |
---|---|
LogUtil()
Creates a new Logger with logging disabled. |
|
LogUtil(File file)
Creates a new Logger which writes to the specified file. |
Method Summary | |
---|---|
void |
close()
Closes the log. |
void |
debug(String logEntry)
If debug is enabled, writes a message to the log. |
void |
debug(String prefix,
String logEntry)
If debug is enabled, writes a message to the log with an optional prefix. |
void |
debug(String logEntry,
Throwable throwable)
If debug is enabled, writes a message with a Throwable to the log file. |
PrintWriter |
getLogWriter()
Returns the current PrintWriter used to write to the log. |
boolean |
isDebug()
Returns whether debug logging is enabled. |
boolean |
isLogging()
Returns whether calls to the logging methods actually write to the log. |
void |
log(String logEntry)
Writes a message to the log. |
void |
log(String prefix,
String logEntry)
Writes a message to the log with an optional prefix. |
void |
log(String prefix,
String logEntry,
Throwable throwable)
Writes a message with a Throwable to the log file. |
void |
log(String logEntry,
Throwable throwable)
Writes a message with a Throwable to the log file. |
void |
log(Throwable throwable)
Writes a Throwable to the log file. |
void |
setDateFormat(DateFormat df)
Sets the date formatter for the logging. |
void |
setDebug(boolean b)
Determines whether to perform debug logging. |
void |
setLog(PrintWriter writer)
Sets the log stream and enables logging. |
void |
setLog(PrintWriter writer,
boolean closeOnExit)
Sets the log stream and enables logging. |
void |
setLogging(boolean b)
Determines whether calls to the logging methods actually write to the log. |
void |
setSeparator(String sep)
Sets the separator string between the date and log message (default ": "). |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LogUtil()
public LogUtil(File file) throws IOException
Logger
which writes to the specified file.
file
- file to which to write log entries
FileNotFoundException
- if specified file is a directory, or cannot
be opened for some reason.
IOException
Method Detail |
---|
public void setDateFormat(DateFormat df)
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG)
df
- DateFormat
instance to use for formatting log messagesDateFormat
public void setSeparator(String sep)
sep
- string to use as separatorpublic void setLog(PrintWriter writer)
PrintWriter
is closed when the close()
method is called.
writer
- PrintWriter
to which to write log entriespublic void setLog(PrintWriter writer, boolean closeOnExit)
writer
- PrintWriter
to which to write log entriescloseOnExit
- whether to close the PrintWriter
when close()
is calledpublic PrintWriter getLogWriter()
PrintWriter
used to write to the log.
public void debug(String logEntry)
logEntry
- message to write as a log entrypublic void debug(String prefix, String logEntry)
prefix
- prefix string for the log entrylogEntry
- message to write as a log entrypublic void debug(String logEntry, Throwable throwable)
Throwable
to the log file.
logEntry
- message to write as a log entrythrowable
- Throwable
instance to log with this entrypublic void log(String logEntry)
logEntry
- message to write as a log entrypublic void log(String prefix, String logEntry)
prefix
- prefix string for the log entrylogEntry
- message to write as a log entrypublic void log(String prefix, String logEntry, Throwable throwable)
Throwable
to the log file.
prefix
- prefix string for the log entrylogEntry
- message to write as a log entrythrowable
- Throwable
instance to log with this entrypublic void log(String logEntry, Throwable throwable)
Throwable
to the log file.
throwable
- Throwable
instance to log with this entrylogEntry
- message to write as a log entrypublic void log(Throwable throwable)
Throwable
to the log file.
throwable
- Throwable
instance to log with this entrypublic void close()
public void setLogging(boolean b)
b
- flag indicating whether to write to the logpublic boolean isLogging()
public void setDebug(boolean b)
b
- flag indicating whether to perform debug loggingpublic boolean isDebug()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |