jimm.twice.util
Class Logger

java.lang.Object
  extended byjimm.twice.util.Logger

public class Logger
extends java.lang.Object

What goes down stairs, alone or in pairs?
Rolls over your neighbor's dog?
What's great for a snack and fits on your back?

It's Log!

Author:
Jim Menard, jimm@io.com

Field Summary
static int DEBUG
           
protected static java.lang.String DEFAULT_LOG_DIR
           
protected static int DEFAULT_LOG_LEVEL
           
protected static java.lang.String DEFAULT_LOG_PREFIX
           
protected  boolean echo
           
static int ERROR
           
static int FATAL
           
protected  java.text.SimpleDateFormat formatter
           
static int INFO
           
protected  java.lang.String logDir
           
protected  int logLevel
           
static int WARNING
           
 
Constructor Summary
protected Logger()
          Constructor.
 
Method Summary
 boolean getEcho()
           
 java.lang.String getLogDir()
           
 int getLogLevel()
           
static Logger instance()
          Returns the single instance of this class.
 void log(int level, java.lang.String logPrefix, java.lang.Object obj)
          Writes a log message.
 void log(int level, java.lang.String logPrefix, java.lang.String location, java.lang.Object obj)
          Writes a log message.
 void setEcho(boolean val)
          Determines if log messages are echoed to System.err.
 void setLogDir(java.lang.String dir)
          Sets (and creates if necessary) the directory that will contain the log files.
 void setLogLevel(int level)
          Sets the level above which log messages will be ignored.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FATAL

public static final int FATAL
See Also:
Constant Field Values

ERROR

public static final int ERROR
See Also:
Constant Field Values

WARNING

public static final int WARNING
See Also:
Constant Field Values

INFO

public static final int INFO
See Also:
Constant Field Values

DEBUG

public static final int DEBUG
See Also:
Constant Field Values

DEFAULT_LOG_DIR

protected static final java.lang.String DEFAULT_LOG_DIR
See Also:
Constant Field Values

DEFAULT_LOG_PREFIX

protected static final java.lang.String DEFAULT_LOG_PREFIX
See Also:
Constant Field Values

DEFAULT_LOG_LEVEL

protected static final int DEFAULT_LOG_LEVEL
See Also:
Constant Field Values

logDir

protected java.lang.String logDir

logLevel

protected int logLevel

formatter

protected java.text.SimpleDateFormat formatter

echo

protected boolean echo
Constructor Detail

Logger

protected Logger()
Constructor. Reads log directory and default log level from properties. Sets echo to true so log messages will be echoed to System.err

Method Detail

instance

public static Logger instance()
Returns the single instance of this class.


getLogDir

public java.lang.String getLogDir()

setLogDir

public void setLogDir(java.lang.String dir)
Sets (and creates if necessary) the directory that will contain the log files. If changed at runtime, further log writes will be output to the new directory.

Parameters:
dir - a directory path

getLogLevel

public int getLogLevel()

setLogLevel

public void setLogLevel(int level)
Sets the level above which log messages will be ignored.

Parameters:
level - one of FATAL, ERROR, WARNING, INFO, or DEBUG

getEcho

public boolean getEcho()

setEcho

public void setEcho(boolean val)
Determines if log messages are echoed to System.err.

Parameters:
val - if true, future log messages will be echoed to System.err.

log

public void log(int level,
                java.lang.String logPrefix,
                java.lang.Object obj)
Writes a log message. If level is <= the current log level, this message is written.

Parameters:
level - the debug level
logPrefix - the beginning of the log file name
obj - the string created by the object's toString is written to the log

log

public void log(int level,
                java.lang.String logPrefix,
                java.lang.String location,
                java.lang.Object obj)
Writes a log message. If level is <= the current log level, this message is written. If echo is true, also writes the message to System.err.

Parameters:
level - the debug level
logPrefix - the beginning of the log file name
location - written after the time stamp, this is usually a method or class name; may be null
obj - the object's string representation is written to the log