edu.rice.cs.util
Class Log

java.lang.Object
  extended by edu.rice.cs.util.Log

public class Log
extends Object

Logging class to record errors or unexpected behavior to a file. The file is created in the current directory, and is only used if the log is enabled. All logs can be enabled at once with the ENABLE_ALL field.

Version:
$Id: Log.java 5175 2010-01-20 08:46:32Z mgricken $

Field Summary
protected  File _file
          The file object for this log.
protected  boolean _isEnabled
          Whether this particular log is enabled in development mode.
protected  String _name
          The filename of this log.
protected  PrintWriter _writer
          PrintWriter to print messages to a file.
 SimpleDateFormat DATE_FORMAT
           
static boolean ENABLE_ALL
           
 
Constructor Summary
Log(File f, boolean isEnabled)
           
Log(String name, boolean isEnabled)
          Creates a new Log with the given name.
 
Method Summary
protected  void _init()
          Creates the log file, if enabled.
 void close()
          Closes a log file.
 boolean isEnabled()
          Returns whether this log is currently enabled.
 void log(String message)
          Prints a message to the log, if enabled.
 void log(String s, StackTraceElement[] trace)
          Prints a message and exception stack trace to the log, if enabled.
 void log(String s, Throwable t)
          Prints a message and exception stack trace to the log, if enabled.
 Date parse(String s)
          Parses a date printed by Date.toString(); returns null if there is a parse error or if there is no date.
 void setEnabled(boolean isEnabled)
          Sets whether this log is enabled.
static String traceToString(StackTraceElement[] trace)
          Converts a stack trace (StackTraceElement[]) to string form
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENABLE_ALL

public static final boolean ENABLE_ALL
See Also:
Constant Field Values

_isEnabled

protected volatile boolean _isEnabled
Whether this particular log is enabled in development mode.


_name

protected volatile String _name
The filename of this log.


_file

protected volatile File _file
The file object for this log.


_writer

protected volatile PrintWriter _writer
PrintWriter to print messages to a file.


DATE_FORMAT

public final SimpleDateFormat DATE_FORMAT
Constructor Detail

Log

public Log(String name,
           boolean isEnabled)
Creates a new Log with the given name. If enabled is true, a file is created in the current directory with the given name.

Parameters:
name - File name for the log
isEnabled - Whether to actively use this log

Log

public Log(File f,
           boolean isEnabled)
Method Detail

_init

protected void _init()
Creates the log file, if enabled.


setEnabled

public void setEnabled(boolean isEnabled)
Sets whether this log is enabled. Only has an effect if the code is in development mode.

Parameters:
isEnabled - Whether to print messages to the log file

isEnabled

public boolean isEnabled()
Returns whether this log is currently enabled.


log

public void log(String message)
Prints a message to the log, if enabled.

Parameters:
message - Message to print.

traceToString

public static String traceToString(StackTraceElement[] trace)
Converts a stack trace (StackTraceElement[]) to string form


log

public void log(String s,
                StackTraceElement[] trace)
Prints a message and exception stack trace to the log, if enabled.

Parameters:
s - Message to print
trace - Stack track to log

log

public void log(String s,
                Throwable t)
Prints a message and exception stack trace to the log, if enabled.

Parameters:
s - Message to print
t - Throwable to log

close

public void close()
Closes a log file.


parse

public Date parse(String s)
Parses a date printed by Date.toString(); returns null if there is a parse error or if there is no date.