|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.OutputStream
java.io.FilterOutputStream
wt.util.LogOutputStream
public class LogOutputStream
A filter output stream for writing log entries. Each line of output is prefixed by the current time and optional stream identifier and thread name.
This filter buffers bytes until a line is received, at which time a log entry is written to the underlying output stream. Each log entry is written to the underlying output stream using a single write operation. This is done in order to minimize the potential for interspersing writes if separate processes are appending to a common file. However, if the underlying FileOutputStream and operating system do not guarantee atomic, sequential appends, then simultaneous writes could still result in lost data.
Output to a LogOutputStream should already be translated
into bytes according to a desired character encoding. The output bytes
are not affected by this filter. This makes the filter an ideal target
for PrintStream or PrintWriter objects which
perform character-to-byte conversions before passing the data to
this output stream. Each LogOutputStream incorporates its own
OutputStreamWriter to translate the additional text being added by the
filter. The system default file encoding is used (same as
PrintStream and PrintWriter) unless
explicity specified as an argument to the constructor.
Currently, this class assumes that a line is terminated by any one of a
line feed ('\n'), a carriage return ('\r'), or a carriage return followed
immediately by a linefeed. This is not a perfect solution. It assumes
these are valid line separators and ignores the possible mapping of
these characters to different byte representations or their occurance
within multi-byte characters. However, most popular multi-byte character
encodings (EUC, Shift-JIS, UTF-8) don't overload these control bytes so
it is a fairly safe assumption. It is a compormise intended to allow newline
characters in strings (such as nested exceptions) to produce multi-line log
entries regardless of default line separator, and to do so in a filter that
can be used with both PrintStream and PrintWriter
classes.
Supported API: true
LogFile| Field Summary |
|---|
| Fields inherited from class java.io.FilterOutputStream |
|---|
out |
| Constructor Summary | |
|---|---|
LogOutputStream(OutputStream out,
String name,
boolean thread_names)
Construct a log output stream. |
|
LogOutputStream(OutputStream out,
String name,
boolean thread_names,
String enc)
Construct a log output stream using a specified character encoding. |
|
| Method Summary | |
|---|---|
static void |
main(String[] argv)
Simple tester. |
void |
write(byte[] b,
int off,
int len)
Writes len bytes from the specified byte array
starting at offset off to the log file. |
void |
write(int b)
Write a byte of data to the log output stream. |
| Methods inherited from class java.io.FilterOutputStream |
|---|
close, flush, write |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public LogOutputStream(OutputStream out,
String name,
boolean thread_names)
out - target byte streamname - optional name to identify this stream (may be null)thread_names - include thread names?
public LogOutputStream(OutputStream out,
String name,
boolean thread_names,
String enc)
throws UnsupportedEncodingException
out - target byte streamname - optional name to identify this streamthread_names - include thread names?enc - character encoding
UnsupportedEncodingException| Method Detail |
|---|
public void write(int b)
throws IOException
write in class FilterOutputStreamb - the byte to be written.
IOException
public void write(byte[] b,
int off,
int len)
throws IOException
len bytes from the specified byte array
starting at offset off to the log file. Each byte
is passed to the write byte method.
write in class FilterOutputStreamb - the data.off - the start offset in the data.len - the number of bytes to write.
IOException
public static void main(String[] argv)
throws IOException
name and thread_names
can be used to specify the name and thread_names
arguments to the constructor.
IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||