com.go.trove.log
Class Log

java.lang.Object
  |
  +--com.go.trove.log.Log
All Implemented Interfaces:
java.util.EventListener, LogListener, java.io.Serializable

public class Log
extends java.lang.Object
implements LogListener, java.io.Serializable

General purpose logging class that operates using a hierarchy of Logs and an event model. All LogEvents are categorized into one of four types: debugging, informational, warning and error. A log event can be generated by writing to one of the four PrintWriter fields provided (debug, info, warn and error), or by calling the debug, info, warn or error methods. Logs can have a parent Log, which by default, receives all the events that the Log generates or receives. If a log is disabled, it will not generate or propagate events. Examples:

 Log log = new Log("test", null);
 log.addLogListener(new LogScribe(new PrintWriter(System.out)));

 log.debug().println("Printing a debugging message");
 log.info("System running");

 Syslog.info().println("Creating child log...");
 Log child = new Log("child", Syslog.log);
 child.warn("This is a system warning...");

 try {
     ...
 }
 catch (Exception e) {
     child.error(e);
 }

 Log saved = new Log("saved", Syslog.log);
 File logDir = new File("/logs/");
 OutputStream out = new DailyFileLogStream(logDir);
 saved.addLogListener(new LogScribe(new PrintWriter(out)));
 saved.info("Saved log file initialized");
 

Version:
27 , 6/28/01
Author:
Brian S O'Neill
See Also:
LogScribe, Syslog, LogEventParsingWriter, DailyFileLogStream, Serialized Form

Constructor Summary
Log(java.lang.String name, Log parent)
          Create a new Log that inherits enabled settings from its parent.
 
Method Summary
 void addLogListener(LogListener listener)
           
 void addRootLogListener(LogListener listener)
          adds a listener to the root log, the log with a null parent
 void applyProperties(java.util.Map properties)
          Understands and applies the following boolean properties.
 java.io.PrintWriter debug()
          Returns a PrintWriter for debug messages.
 void debug(java.lang.String s)
          Simple method for logging a single debugging message.
 void debug(java.lang.Throwable t)
          Simple method for logging a single debugging exception.
 java.io.PrintWriter error()
          Returns a PrintWriter for error messages.
 void error(java.lang.String s)
          Simple method for logging a single error message.
 void error(java.lang.Throwable t)
          Simple method for logging a single error exception.
 Log[] getChildren()
          Returns a copy of the children Logs.
 java.lang.String getDescription()
          Returns a brief description of this Log.
 java.lang.String getName()
          Returns null if this Log has no name.
 java.io.PrintWriter info()
          Returns a PrintWriter for information messages.
 void info(java.lang.String s)
          Simple method for logging a single information message.
 void info(java.lang.Throwable t)
          Simple method for logging a single information exception.
 boolean isDebugEnabled()
          Returns true if debug events for this Log are enabled.
 boolean isEnabled()
          Returns true if this Log is enabled.
 boolean isErrorEnabled()
          Returns true if error events for this Log are enabled.
 boolean isInfoEnabled()
          Returns true if info events for this Log are enabled.
 boolean isWarnEnabled()
          Returns true if warn events for this Log are enabled.
 void logException(LogEvent e)
          If this Log is enabled, then dispatch the LogEvent to all of its listeners as a logged exception.
 void logMessage(LogEvent e)
          If this Log is enabled, then dispatch the LogEvent to all of its listeners as a logged message.
 void removeLogListener(LogListener listener)
           
 void removeRootLogListener(LogListener listener)
           
 void setDebugEnabled(boolean enabled)
          When debug is enabled, this Log is enabled and all parent Logs are enabled.
 void setDescription(java.lang.String desc)
          Set the log's description text.
 void setEnabled(boolean enabled)
          When this Log is enabled, all parent Logs are also enabled.
 void setErrorEnabled(boolean enabled)
          When error is enabled, this Log is enabled and all parent Logs are enabled.
 void setInfoEnabled(boolean enabled)
          When info is enabled, this Log is enabled and all parent Logs are enabled.
 void setWarnEnabled(boolean enabled)
          When warn is enabled, this Log is enabled and all parent Logs are enabled.
 java.lang.String toString()
          Returns a short description of this log.
 java.io.PrintWriter warn()
          Returns a PrintWriter for warning messages.
 void warn(java.lang.String s)
          Simple method for logging a single warning message.
 void warn(java.lang.Throwable t)
          Simple method for logging a single warning exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Log

public Log(java.lang.String name,
           Log parent)
Create a new Log that inherits enabled settings from its parent. If no parent is specified, then the Log is fully enabled. If a parent is specified, then it is added automatically as a listener to this Log.
Parameters:
name - The optional name of this Log.
parent - The parent Log that will be added as a LogListener to this Log. If null, then this Log has no parent Log.
Method Detail

addRootLogListener

public void addRootLogListener(LogListener listener)
adds a listener to the root log, the log with a null parent

removeRootLogListener

public void removeRootLogListener(LogListener listener)

addLogListener

public void addLogListener(LogListener listener)

removeLogListener

public void removeLogListener(LogListener listener)

logMessage

public void logMessage(LogEvent e)
If this Log is enabled, then dispatch the LogEvent to all of its listeners as a logged message.
Specified by:
logMessage in interface LogListener

logException

public void logException(LogEvent e)
If this Log is enabled, then dispatch the LogEvent to all of its listeners as a logged exception.
Specified by:
logException in interface LogListener

debug

public java.io.PrintWriter debug()
Returns a PrintWriter for debug messages.

debug

public void debug(java.lang.String s)
Simple method for logging a single debugging message.

debug

public void debug(java.lang.Throwable t)
Simple method for logging a single debugging exception.

info

public java.io.PrintWriter info()
Returns a PrintWriter for information messages.

info

public void info(java.lang.String s)
Simple method for logging a single information message.

info

public void info(java.lang.Throwable t)
Simple method for logging a single information exception.

warn

public java.io.PrintWriter warn()
Returns a PrintWriter for warning messages.

warn

public void warn(java.lang.String s)
Simple method for logging a single warning message.

warn

public void warn(java.lang.Throwable t)
Simple method for logging a single warning exception.

error

public java.io.PrintWriter error()
Returns a PrintWriter for error messages.

error

public void error(java.lang.String s)
Simple method for logging a single error message.

error

public void error(java.lang.Throwable t)
Simple method for logging a single error exception.

getChildren

public Log[] getChildren()
Returns a copy of the children Logs.

getName

public java.lang.String getName()
Returns null if this Log has no name.

getDescription

public java.lang.String getDescription()
Returns a brief description of this Log. By default, returns the name.

setDescription

public void setDescription(java.lang.String desc)
Set the log's description text.

isEnabled

public boolean isEnabled()
Returns true if this Log is enabled. If log is disabled, then no log events of any kind are generated or propagated to listeners.

setEnabled

public void setEnabled(boolean enabled)
When this Log is enabled, all parent Logs are also enabled. When this Log is disabled, parent Logs are unaffected.

isDebugEnabled

public boolean isDebugEnabled()
Returns true if debug events for this Log are enabled. If debug events are disabled, then no debug log events are generated, but they can be propagated to listeners.

setDebugEnabled

public void setDebugEnabled(boolean enabled)
When debug is enabled, this Log is enabled and all parent Logs are enabled. Disabling debug only affects this Log's debug state.

isInfoEnabled

public boolean isInfoEnabled()
Returns true if info events for this Log are enabled. If info events are disabled, then no info log events are generated, but they can be propagated to listeners.

setInfoEnabled

public void setInfoEnabled(boolean enabled)
When info is enabled, this Log is enabled and all parent Logs are enabled. Disabling info only affects this Log's info state.

isWarnEnabled

public boolean isWarnEnabled()
Returns true if warn events for this Log are enabled. If warn events are disabled, then no warn log events are generated, but they can be propagated to listeners.

setWarnEnabled

public void setWarnEnabled(boolean enabled)
When warn is enabled, this Log is enabled and all parent Logs are enabled. Disabling warn only affects this Log's warn state.

isErrorEnabled

public boolean isErrorEnabled()
Returns true if error events for this Log are enabled. If error events are disabled, then no error log events are generated, but they can be propagated to listeners.

setErrorEnabled

public void setErrorEnabled(boolean enabled)
When error is enabled, this Log is enabled and all parent Logs are enabled. Disabling error only affects this Log's error state.

applyProperties

public void applyProperties(java.util.Map properties)
Understands and applies the following boolean properties. True is the default value if the value doesn't equal "false", ignoring case.

toString

public java.lang.String toString()
Returns a short description of this log.
Overrides:
toString in class java.lang.Object