com.xmlmind.util
Class Log

java.lang.Object
  extended by com.xmlmind.util.Log

public final class Log
extends java.lang.Object

A simple log facility which implements the following services:

In addition to the above services, this log facility can act as a facade for real logging tools such as those found in java.util.logging.Logger.

This class is thread-safe.


Nested Class Summary
static class Log.Item
          A buffered item.
static class Log.Level
          Log levels.
static interface Log.Recorder
          Underlying logger.
static interface Log.RecorderFactory
          Underlying logger factory.
static class Log.RecorderFactoryImpl
          Creates and returns Log.RecorderImpls.
static class Log.RecorderImpl
          A message recorder that does not nothing at.
 
Field Summary
static int DEFAULT_CAPACITY
          Default buffering capacity (1,000).
static int MAX_CAPACITY
          Maximum buffering capacity (100,000).
 Log.Recorder recorder
          The underlying logger used by this Log object.
 
Method Summary
 void clear()
          Removes all buffered items.
 void debug(java.lang.String message)
          Logs specified message at level Log.Level.DEBUG.
 void error(java.lang.String message)
          Logs specified message at level Log.Level.ERROR.
 Log.Item[] get()
          Returns all buffered items.
 Log.Item[] get(int maxCount)
          Returns last buffered items.
 Log.Item[] get(Log.Level maxLevel)
          Returns all buffered items having at most specified level.
 Log.Item[] get(Log.Level maxLevel, int maxCount)
          Returns last buffered items having at most specified level.
 int getCapacity()
          Returns buffering capacity.
static Log getLog(java.lang.String name)
          Returns the log having specified name.
static java.lang.String[] getNames()
          Returns the names of all logs returned by getLog(java.lang.String).
static Log.RecorderFactory getRecorderFactory()
          Returns currently used RecorderFactory.
 void info(java.lang.String message)
          Logs specified message at level Log.Level.INFO.
 void log(Log.Level level, java.lang.String message)
          Logs specified message at specified level.
 void setCapacity(int capacity)
          Specifies buffering capacity.
static void setRecorderFactory(Log.RecorderFactory factory)
          Specifies which RecorderFactory to use.
 void verbose(java.lang.String message)
          Logs specified message at level Log.Level.VERBOSE.
 void warning(java.lang.String message)
          Logs specified message at level Log.Level.WARNING.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY
Default buffering capacity (1,000).

See Also:
Constant Field Values

MAX_CAPACITY

public static final int MAX_CAPACITY
Maximum buffering capacity (100,000).

See Also:
Constant Field Values

recorder

public final Log.Recorder recorder
The underlying logger used by this Log object.

Method Detail

setRecorderFactory

public static void setRecorderFactory(Log.RecorderFactory factory)
Specifies which RecorderFactory to use. Specify null to use the default implementation.


getRecorderFactory

public static Log.RecorderFactory getRecorderFactory()
Returns currently used RecorderFactory.


getLog

public static Log getLog(java.lang.String name)
Returns the log having specified name. Creates one if needed to.

A log name may be anything string. However some related utilities support qualified names. A qualified name has the following syntax:

qualified_name -> [ namespace ]? local_part
namespace -> '{' [ string ]? '}'
local_part -> string

Note that {}foo and foo are equivalent.


getNames

public static java.lang.String[] getNames()
Returns the names of all logs returned by getLog(java.lang.String).


error

public void error(java.lang.String message)
Logs specified message at level Log.Level.ERROR.


warning

public void warning(java.lang.String message)
Logs specified message at level Log.Level.WARNING.


info

public void info(java.lang.String message)
Logs specified message at level Log.Level.INFO.


verbose

public void verbose(java.lang.String message)
Logs specified message at level Log.Level.VERBOSE.


debug

public void debug(java.lang.String message)
Logs specified message at level Log.Level.DEBUG.


log

public void log(Log.Level level,
                java.lang.String message)
Logs specified message at specified level.


setCapacity

public void setCapacity(int capacity)
Specifies buffering capacity. Cannot exceed MAX_CAPACITY.

When the number of buffered items has reached this capacity, ``oldest''item is discarded to make room for newly buffered item.


getCapacity

public int getCapacity()
Returns buffering capacity.


get

public Log.Item[] get()
Returns all buffered items.


get

public Log.Item[] get(int maxCount)
Returns last buffered items.

Parameters:
maxCount - return at most this number of items
Returns:
a possibly empty array of items, first item being the ``oldest one''

get

public Log.Item[] get(Log.Level maxLevel)
Returns all buffered items having at most specified level.

Parameters:
maxLevel - maximum level (inclusive) for returned items
Returns:
a possibly empty array of items, first item being the ``oldest one''

get

public Log.Item[] get(Log.Level maxLevel,
                      int maxCount)
Returns last buffered items having at most specified level.

Parameters:
maxLevel - maximum level (inclusive) for returned items
maxCount - return at most this number of items
Returns:
a possibly empty array of items, first item being the ``oldest one''

clear

public void clear()
Removes all buffered items.