public class Log extends Object
To log a message, you call one of the get
methods of this class to
yield a LogWriter
object. You can then call methods like LogWriter.println(String)
to log a line of text. A typical invocation is
Log.get().println("Buffer of length " + length + " allocated.");
This logs the given text using the default source string, and under the default
category, and timestamped with the current time. You can reuse the
LogWriter
, but the timestamp, source, and category won't change. You
should get a fresh LogWriter
.
Sources identify independent origins of log messages, such as
independent threads in a program, or independent programs. Sources are just strings.
If you don't specify a source, you get a default source. You can set the default
source with setDefaultSource(java.lang.String)
. You always get a source with every
message, even if it's a default source. If you don't otherwise set a default source
string, the source is "app".
Categories identify different classes or priorites of messages.
Categories can be simple strings like "warning" or "debug", or they can be complex
objects. You get to define your categories. Your group ought to agree on categories,
though. If you don't specify a category, you get a default category. You can set the
default category with setDefaultCategory(java.lang.Object)
. If you don't call that method, the
default category is the String object "message".
Streams identify independent activities within a program, which
often have transient lifespans. They're not separate output streams, but
instead are separate, named entities representing separate activities (although a
LogListener
may put messages into separate output streams identified by each
stream). Activity streams are identified by strings. To indicate the start and stop
of streams, call startStream(java.lang.String, java.util.Date, java.lang.String)
and stopStream(java.lang.String)
. These send
stream-started and stream-stopped events to the log listeners, who may choose to pay
attention to them or ignore them. You can use streams to indicate to the log the start
and the stop of activities such as an analyst examining the system, or a server
handling a particular client.
All messages logged with this class go to one or more LogListener
objects.
A LogListener accepts logging events, such as a message being logged, and does
something with it, such as writing the message to a file. Call addLogListener(org.apache.oodt.commons.io.LogListener)
to add a log listener. Logging of a message, starting a stream, and stopping a stream
all get turned into LogEvent
s and are multicasted to every registered listener.
The logging facility bootstraps itself with one or more log listeners specified by
the system property org.apache.oodt.commons.io.Log.loggers
. This property must be a
space-separated list of complete class names. The logging facility will create an
object of each class listed and add it as if you had called
addLogListener
. (You can specify system properties on the command line or
in the applet tag.)
LogListener
,
LogWriter
Modifier and Type | Method and Description |
---|---|
static void |
addLogListener(LogListener listener)
Add a log listener.
|
static LogWriter |
get()
Get a writer to log messages.
|
static LogWriter |
get(Date timestamp,
String source,
Object category)
Get a writer to log messages.
|
static LogWriter |
get(Object category)
Get a writer to log messages.
|
static Object |
getDefaultCategory()
Get the default category.
|
static String |
getDefaultSource()
Get the default source.
|
static void |
removeLogListener(LogListener listener)
Remove a log listener.
|
static void |
setDefaultCategory(Object category)
Set the default category.
|
static void |
setDefaultSource(String source)
Set the default source.
|
static void |
startStream(String stream,
Date timestamp,
String source)
Start a new log stream.
|
static void |
stopStream(String stream)
Stop a stream.
|
public static LogWriter get()
public static LogWriter get(Object category)
category
- The messages' category.public static LogWriter get(Date timestamp, String source, Object category)
timestamp
- The time for messages logged with the returned writer.source
- The source of the log message.category
- The messages' category.public static void startStream(String stream, Date timestamp, String source)
LogListener
s that a new logging stream has
started.stream
- The name of the stream.timestamp
- The time the stream started. To use the current time, pass a new Date
object.source
- A string identifying who or what started the stream.public static void stopStream(String stream)
LogListener
s that a logging stream has stopped.stream
- The name of the stream that stopped.public static void setDefaultSource(String source)
source
- The new default source label.public static String getDefaultSource()
public static void setDefaultCategory(Object category)
category
- The new default category object.public static Object getDefaultCategory()
public static void addLogListener(LogListener listener)
listener
- The listener to add.public static void removeLogListener(LogListener listener)
listener
- The listener to remove.Copyright © 1999–2017 Apache OODT. All rights reserved.