org.progeeks.util.log
Class Log

java.lang.Object
  extended by org.progeeks.util.log.Log

public class Log
extends java.lang.Object

System logging class. Allows for multiple log levels and a hierarchy of named categories. Each category can have its own log format. Example code:

  public class MyTestClass {
      static Log log = Log.getLog( MyTestClass.class );

      public void someMethod() {
          log.debug( "Entering someMethod()" );
          log.info( "Some operation being performed." );
      }
  }
  

Version:
$Revision: 1.12 $
Author:
Paul Speed

Field Summary
static java.lang.String DEFAULT_CONFIG
           
static java.lang.String KEY_LOG_CONFIG
           
 
Method Summary
static void addLogListener(LogListener listener, java.lang.Class c, LogLevel level)
          Adds a log listener for the specified class and level.
static void addLogListener(LogListener listener, LogLevel level)
          Adds a log listener to the root log category using the specified level threshold.
static void addLogListener(LogListener listener, java.lang.String category, LogLevel level)
          Adds a log listener for the specified category and level.
static java.util.Iterator categoryNames()
          Returns an iterator over the current log category names.
 void debug(java.lang.Object message)
          Log a message at the debug priority level.
 void debug(java.lang.Object message, java.lang.Throwable t)
          Log a message at the debug priority level including the stack trace of the specified Throwable.
static void end()
          Threads should call this to remove the diagnostic context before exitting.
 void error(java.lang.Object message)
          Log a message at the error priority level.
 void error(java.lang.Object message, java.lang.Throwable t)
          Log a message at the error priority level including the stack trace of the specified Throwable.
static boolean exists(java.lang.Class c)
          Returns true if the specified class already has a log target.
static boolean exists(java.lang.String category)
          Returns true if the specified category already has a log target.
 void fatal(java.lang.Object message)
          Log a message at the fatal priority level.
 void fatal(java.lang.Object message, java.lang.Throwable t)
          Log a message at the fatal priority level including the stack trace of the specified Throwable.
 java.lang.String getCategoryName()
          Returns the current category name for this Log instance.
 LogLevel getEffectiveLogLevel()
          Returns the current effictive logging level of this log.
static Log getLog()
          Gets a log instance using the caller's class name as the category name.
static Log getLog(java.lang.Class c)
          Shorthand for getLog( c.getName() );
static Log getLog(java.lang.String categoryName)
          Gets a log instance for writing messages of the specified category.
 LogLevel getLogLevel()
          Returns the current logging level of this log.
static Log getRootLog()
          Returns the root log object.
 void info(java.lang.Object message)
          Log a message at the info priority level.
 void info(java.lang.Object message, java.lang.Throwable t)
          Log a message at the info priority level including the stack trace of the specified Throwable.
static void initialize()
          Initializes the Logger with basic configuration.
 boolean isDebugEnabled()
          Returns true if the current category is logging at the debug level.
 boolean isInfoEnabled()
          Returns true if the current category is logging at the info level.
 void log(java.lang.Object message, LogLevel level)
          Log a message at the specified priority level.
 void log(java.lang.Object message, LogLevel level, java.lang.Throwable t)
          Log a message at the specified priority level including the stack trace of the specified Throwable.
static java.lang.String pop()
          Clients should call this method before leaving a diagnostic context.
static void push(java.lang.String context)
          Pushes a new diagnostic context onto the context stack.
 void setLogLevel(LogLevel level)
          Set the logging level of this log.
 void trace(java.lang.Object message)
          Log a message at the trace priority level.
 void trace(java.lang.Object message, java.lang.Throwable t)
          Log a message at the trace priority level including the stack trace of the specified Throwable.
 void warn(java.lang.Object message)
          Log a message at the warn priority level.
 void warn(java.lang.Object message, java.lang.Throwable t)
          Log a message at the warn priority level including the stack trace of the specified Throwable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_LOG_CONFIG

public static final java.lang.String KEY_LOG_CONFIG
See Also:
Constant Field Values

DEFAULT_CONFIG

public static final java.lang.String DEFAULT_CONFIG
See Also:
Constant Field Values
Method Detail

initialize

public static void initialize()
Initializes the Logger with basic configuration. If the "log.config" System property is set then it will use that value as a configuration file name. Otherwise, the default configuration will be used.


getLog

public static Log getLog(java.lang.String categoryName)
Gets a log instance for writing messages of the specified category. If a name refers to an already retrieved category then the log objects will refer to the same category instance. Note: right now that doesn't make much since, but when log4j is implemented then categories become a very powerful log filter.

Parameters:
categoryName - The name of the category to which the logger will be associated.

getLog

public static Log getLog(java.lang.Class c)
Shorthand for getLog( c.getName() );

Parameters:
c - The class used to retrieve the category name.

getLog

public static Log getLog()
Gets a log instance using the caller's class name as the category name.


getRootLog

public static Log getRootLog()
Returns the root log object.


exists

public static boolean exists(java.lang.String category)
Returns true if the specified category already has a log target.


exists

public static boolean exists(java.lang.Class c)
Returns true if the specified class already has a log target.


categoryNames

public static java.util.Iterator categoryNames()
Returns an iterator over the current log category names.


addLogListener

public static void addLogListener(LogListener listener,
                                  LogLevel level)
Adds a log listener to the root log category using the specified level threshold.


addLogListener

public static void addLogListener(LogListener listener,
                                  java.lang.String category,
                                  LogLevel level)
Adds a log listener for the specified category and level.


addLogListener

public static void addLogListener(LogListener listener,
                                  java.lang.Class c,
                                  LogLevel level)
Adds a log listener for the specified class and level.


push

public static void push(java.lang.String context)
Pushes a new diagnostic context onto the context stack. All logged messages in this thread will now be within this context.

Parameters:
context - The name of the diagnostic context.

pop

public static java.lang.String pop()
Clients should call this method before leaving a diagnostic context.

Returns:
The previously pushed diagnostic context.

end

public static void end()
Threads should call this to remove the diagnostic context before exitting.


getCategoryName

public java.lang.String getCategoryName()
Returns the current category name for this Log instance.


setLogLevel

public void setLogLevel(LogLevel level)
Set the logging level of this log.


getLogLevel

public LogLevel getLogLevel()
Returns the current logging level of this log. May be null if this Log doesn't have a specific level defined.


getEffectiveLogLevel

public LogLevel getEffectiveLogLevel()
Returns the current effictive logging level of this log. If the local level is null then it will search up the hierarchy for the inherited level.


trace

public void trace(java.lang.Object message)
Log a message at the trace priority level. This is finer grained than debug.

Parameters:
message - The message object to log.

trace

public void trace(java.lang.Object message,
                  java.lang.Throwable t)
Log a message at the trace priority level including the stack trace of the specified Throwable.

Parameters:
message - The message object to log.
t - The throwable to log, including its stack trace.

debug

public void debug(java.lang.Object message)
Log a message at the debug priority level.

Parameters:
message - The message object to log.

debug

public void debug(java.lang.Object message,
                  java.lang.Throwable t)
Log a message at the debug priority level including the stack trace of the specified Throwable.

Parameters:
message - The message object to log.
t - The throwable to log, including its stack trace.

error

public void error(java.lang.Object message)
Log a message at the error priority level.

Parameters:
message - The message object to log.

error

public void error(java.lang.Object message,
                  java.lang.Throwable t)
Log a message at the error priority level including the stack trace of the specified Throwable.

Parameters:
message - The message object to log.
t - The throwable to log, including its stack trace.

fatal

public void fatal(java.lang.Object message)
Log a message at the fatal priority level.

Parameters:
message - The message object to log.

fatal

public void fatal(java.lang.Object message,
                  java.lang.Throwable t)
Log a message at the fatal priority level including the stack trace of the specified Throwable.

Parameters:
message - The message object to log.
t - The throwable to log, including its stack trace.

info

public void info(java.lang.Object message)
Log a message at the info priority level.

Parameters:
message - The message object to log.

info

public void info(java.lang.Object message,
                 java.lang.Throwable t)
Log a message at the info priority level including the stack trace of the specified Throwable.

Parameters:
message - The message object to log.
t - The throwable to log, including its stack trace.

warn

public void warn(java.lang.Object message)
Log a message at the warn priority level.

Parameters:
message - The message object to log.

warn

public void warn(java.lang.Object message,
                 java.lang.Throwable t)
Log a message at the warn priority level including the stack trace of the specified Throwable.

Parameters:
message - The message object to log.
t - The throwable to log, including its stack trace.

log

public void log(java.lang.Object message,
                LogLevel level)
Log a message at the specified priority level.

Parameters:
message - The message object to log.
level - The level at which to log the message.

log

public void log(java.lang.Object message,
                LogLevel level,
                java.lang.Throwable t)
Log a message at the specified priority level including the stack trace of the specified Throwable.

Parameters:
message - The message object to log.
level - The level at which to log the message.
t - The throwable to log, including its stack trace.

isDebugEnabled

public boolean isDebugEnabled()
Returns true if the current category is logging at the debug level.


isInfoEnabled

public boolean isInfoEnabled()
Returns true if the current category is logging at the info level.



Copyright © 2002-2003 Paul Speed. All Rights Reserved.