public class LogUtil extends Object
| Constructor and Description |
|---|
LogUtil()
Creates a new Logger with logging disabled.
|
LogUtil(File file)
Creates a new
Logger which writes to the specified file. |
| Modifier and Type | Method and Description |
|---|---|
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 ": ").
|
protected void |
writeLogEntry(String logEntry)
Writes a message to the log.
|
public LogUtil()
public LogUtil(File file) throws IOException
Logger which writes to the specified file.file - file to which to write log entriesFileNotFoundException - if specified file is a directory, or cannot
be opened for some reason.IOExceptionpublic void setDateFormat(DateFormat df)
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG)df - DateFormat instance to use for formatting log messagesDateFormatpublic void setSeparator(String sep)
sep - string to use as separatorpublic final 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.PrintWriter used to write to the logprotected void writeLogEntry(String logEntry)
logEntry - message to write as a log entrypublic 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()
Copyright © 2014. All rights reserved.