Fields Summary |
---|
private static Hashtable | knowntable mapping known log names to log stream objects |
private static PrintStream | defaultStreamdefault output stream for new logs |
private String | namelog name for this log |
private OutputStream | logOutstream where output of this log is sent to |
private OutputStreamWriter | logWriterstring writer for writing message prefixes to log stream |
private StringBuffer | bufferstring buffer used for constructing log message prefixes |
private ByteArrayOutputStream | bufOutstream used for buffering lines |
public static final int | SILENTlog level constant (no logging). |
public static final int | BRIEFlog level constant (brief logging). |
public static final int | VERBOSElog level constant (verbose logging). |
Methods Summary |
---|
public static synchronized java.io.PrintStream | getDefaultStream()Return the current default stream for new logs.
return defaultStream;
|
public synchronized java.io.OutputStream | getOutputStream()Return the current stream to which output from this log is sent.
return logOut;
|
public static java.rmi.server.LogStream | log(java.lang.String name)Return the LogStream identified by the given name. If
a log corresponding to "name" does not exist, a log using
the default stream is created.
LogStream stream;
synchronized (known) {
stream = (LogStream)known.get(name);
if (stream == null) {
stream = new LogStream(name, defaultStream);
}
known.put(name, stream);
}
return stream;
|
public static int | parseLevel(java.lang.String s)Convert a string name of a logging level to its internal
integer representation.
if ((s == null) || (s.length() < 1))
return -1;
try {
return Integer.parseInt(s);
} catch (NumberFormatException e) {
}
if (s.length() < 1)
return -1;
if ("SILENT".startsWith(s.toUpperCase()))
return SILENT;
else if ("BRIEF".startsWith(s.toUpperCase()))
return BRIEF;
else if ("VERBOSE".startsWith(s.toUpperCase()))
return VERBOSE;
return -1;
|
public static synchronized void | setDefaultStream(java.io.PrintStream newDefault)Set the default stream for new logs.
defaultStream = newDefault;
|
public synchronized void | setOutputStream(java.io.OutputStream out)Set the stream to which output from this log is sent.
logOut = out;
// Maintain an OutputStreamWriter with default CharToByteConvertor
// (just like new PrintStream) for writing log message prefixes.
logWriter = new OutputStreamWriter(logOut);
|
public java.lang.String | toString()Return log name as string representation.
return name;
|
public void | write(int b)Write a byte of data to the stream. If it is not a newline, then
the byte is appended to the internal buffer. If it is a newline,
then the currently buffered line is sent to the log's output
stream, prefixed with the appropriate logging information.
if (b == '\n") {
// synchronize on "this" first to avoid potential deadlock
synchronized (this) {
synchronized (logOut) {
// construct prefix for log messages:
buffer.setLength(0);;
buffer.append( // date/time stamp...
(new Date()).toString());
buffer.append(':");
buffer.append(name); // ...log name...
buffer.append(':");
buffer.append(Thread.currentThread().getName());
buffer.append(':"); // ...and thread name
try {
// write prefix through to underlying byte stream
logWriter.write(buffer.toString());
logWriter.flush();
// finally, write the already converted bytes of
// the log message
bufOut.writeTo(logOut);
logOut.write(b);
logOut.flush();
} catch (IOException e) {
setError();
} finally {
bufOut.reset();
}
}
}
}
else
super.write(b);
|
public void | write(byte[] b, int off, int len)Write a subarray of bytes. Pass each through write byte method.
if (len < 0)
throw new ArrayIndexOutOfBoundsException(len);
for (int i = 0; i < len; ++ i)
write(b[off + i]);
|