public final class Log extends Object
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.
Modifier and Type | Class and Description |
---|---|
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.RecorderImpl s. |
static class |
Log.RecorderImpl
A message recorder that does not nothing at.
|
Modifier and Type | Field and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all buffered items.
|
void |
debug(String message)
Logs specified message at level
Log.Level.DEBUG . |
void |
error(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(String name)
Returns the log having specified name.
|
static String[] |
getNames()
Returns the names of all logs returned by
getLog(java.lang.String) . |
static Log.RecorderFactory |
getRecorderFactory()
Returns currently used RecorderFactory.
|
void |
info(String message)
Logs specified message at level
Log.Level.INFO . |
void |
log(Log.Level level,
String message)
Logs specified message at specified level.
|
void |
print(boolean mostRecentFirst,
boolean withDate,
PrintStream out)
Prints all logged items to specified output stream.
|
void |
setCapacity(int capacity)
Specifies buffering capacity.
|
static void |
setRecorderFactory(Log.RecorderFactory factory)
Specifies which RecorderFactory to use.
|
void |
verbose(String message)
Logs specified message at level
Log.Level.VERBOSE . |
void |
warning(String message)
Logs specified message at level
Log.Level.WARNING . |
public static final int DEFAULT_CAPACITY
public static final int MAX_CAPACITY
public final Log.Recorder recorder
public static void setRecorderFactory(Log.RecorderFactory factory)
null
to use the default implementation.public static Log.RecorderFactory getRecorderFactory()
public static Log getLog(String name)
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.
public static String[] getNames()
getLog(java.lang.String)
.public void error(String message)
Log.Level.ERROR
.public void warning(String message)
Log.Level.WARNING
.public void info(String message)
Log.Level.INFO
.public void verbose(String message)
Log.Level.VERBOSE
.public void debug(String message)
Log.Level.DEBUG
.public void setCapacity(int capacity)
MAX_CAPACITY
.
When the number of buffered items has reached this capacity, ``oldest''item is discarded to make room for newly buffered item.
public int getCapacity()
public Log.Item[] get()
public Log.Item[] get(int maxCount)
maxCount
- return at most this number of itemspublic Log.Item[] get(Log.Level maxLevel)
maxLevel
- maximum level (inclusive) for returned itemspublic Log.Item[] get(Log.Level maxLevel, int maxCount)
maxLevel
- maximum level (inclusive) for returned itemsmaxCount
- return at most this number of itemspublic void clear()
public void print(boolean mostRecentFirst, boolean withDate, PrintStream out)
mostRecentFirst
- if true
, print most recently
logged items first; if false
, print items in the order
in which they have been loggedwithDate
- if true
, each printed line starts with
the log date of the itemout
- output stream