|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.bluemarsh.jswat.Log
Class for providing a general logging facility. An instance of this class be attached to multiple OutputStreams or Writers for the log messages to be sent to. This object is synchronized in various places to ensure only reasonable output is generated.
The Log class can automatically flush the buffer contents to
the attach streams and writers if its start()
method
is called. This will create a flusher thread that flushes the
buffer whenever something is written to the Log. Alternatively,
the buffer can be flushed manually by calling flush()
.
Field Summary | |
protected java.lang.Object |
bufferLock
Object used to synchronize access to the logBuffer reference. |
protected static int |
DEFAULT_BUFFER_LEN
Default length for the log buffer. |
protected java.lang.Object |
flushLock
Object used to synchronize flushing the buffer. |
protected java.lang.StringBuffer |
logBuffer
The messages pending writing to the writers and output streams. |
protected java.util.List |
oslist
List of all the OutputStream objects. |
protected java.lang.Thread |
runningThread
Thread that handles the flushing of the buffer. |
protected java.util.List |
wlist
List of all the Writer objects. |
Constructor Summary | |
Log()
Constructs a Log object. |
Method Summary | |
void |
attach(java.io.OutputStream os)
Attach to an output stream in order to write log messages to it. |
void |
attach(java.io.Writer w)
Attach to a writer in order to write log messages to it. |
void |
detach(java.io.OutputStream os)
Detach an output stream from this log. |
void |
detach(java.io.Writer w)
Remove a writer from this log. |
boolean |
flush()
Takes the log buffer and writes its contents to the writers. |
void |
run()
Run the buffer flusher. |
void |
start()
Start the Log flusher thread, using normal thread priority. |
void |
start(int priority)
Start the Log flusher thread with the given thread priority. |
void |
stop()
Stop the flusher thread synchronously. |
void |
write(java.lang.String s)
Write a string to the log (without a linefeed). |
void |
writeln(java.lang.String s)
Write a string to the log (with a linefeed). |
void |
writeStackTrace(java.lang.Throwable t)
Write the given throwable's stack trace to the Log. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final int DEFAULT_BUFFER_LEN
protected java.util.List oslist
protected java.util.List wlist
protected java.lang.StringBuffer logBuffer
protected java.lang.Object bufferLock
protected java.lang.Object flushLock
protected java.lang.Thread runningThread
Constructor Detail |
public Log()
start()
method is called.Method Detail |
public void attach(java.io.OutputStream os)
os
- output stream to write topublic void attach(java.io.Writer w)
w
- writer to write topublic void detach(java.io.OutputStream os)
os
- output stream to detach frompublic void detach(java.io.Writer w)
w
- writer to detach frompublic boolean flush()
public void run()
run
in interface java.lang.Runnable
public void start(int priority)
priority
- Thread priority.stop()
public void start()
stop()
public void stop()
public void write(java.lang.String s)
s
- string to write to logpublic void writeln(java.lang.String s)
s
- string to write to logpublic void writeStackTrace(java.lang.Throwable t)
t
- throwable to print stack for.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |