Methods Summary |
---|
public synchronized void | close()Close the current output stream.
The Formatter's "tail" string is written to the stream before it
is closed. In addition, if the Formatter's "head" string has not
yet been written to the stream, it will be written before the
"tail" string.
flushAndClose();
|
private void | configure()
// Private method to configure a StreamHandler from LogManager
// properties and/or default values as specified in the class
// javadoc.
LogManager manager = LogManager.getLogManager();
String cname = getClass().getName();
setLevel(manager.getLevelProperty(cname +".level", Level.INFO));
setFilter(manager.getFilterProperty(cname +".filter", null));
setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter()));
try {
setEncoding(manager.getStringProperty(cname +".encoding", null));
} catch (Exception ex) {
try {
setEncoding(null);
} catch (Exception ex2) {
// doing a setEncoding with null should always work.
// assert false;
}
}
|
public synchronized void | flush()Flush any buffered messages.
if (writer != null) {
try {
writer.flush();
} catch (Exception ex) {
// We don't want to throw an exception here, but we
// report the exception to any registered ErrorManager.
reportError(null, ex, ErrorManager.FLUSH_FAILURE);
}
}
|
private synchronized void | flushAndClose()
checkAccess();
if (writer != null) {
try {
if (!doneHeader) {
writer.write(getFormatter().getHead(this));
doneHeader = true;
}
writer.write(getFormatter().getTail(this));
writer.flush();
writer.close();
} catch (Exception ex) {
// We don't want to throw an exception here, but we
// report the exception to any registered ErrorManager.
reportError(null, ex, ErrorManager.CLOSE_FAILURE);
}
writer = null;
output = null;
}
|
public boolean | isLoggable(java.util.logging.LogRecord record)Check if this Handler would actually log a given LogRecord.
This method checks if the LogRecord has an appropriate level and
whether it satisfies any Filter. It will also return false if
no output stream has been assigned yet or the LogRecord is Null.
if (writer == null || record == null) {
return false;
}
return super.isLoggable(record);
|
public synchronized void | publish(java.util.logging.LogRecord record)Format and publish a LogRecord.
The StreamHandler first checks if there is an OutputStream
and if the given LogRecord has at least the required log level.
If not it silently returns. If so, it calls any associated
Filter to check if the record should be published. If so,
it calls its Formatter to format the record and then writes
the result to the current output stream.
If this is the first LogRecord to be written to a given
OutputStream, the Formatter's "head" string is
written to the stream before the LogRecord is written.
if (!isLoggable(record)) {
return;
}
String msg;
try {
msg = getFormatter().format(record);
} catch (Exception ex) {
// We don't want to throw an exception here, but we
// report the exception to any registered ErrorManager.
reportError(null, ex, ErrorManager.FORMAT_FAILURE);
return;
}
try {
if (!doneHeader) {
writer.write(getFormatter().getHead(this));
doneHeader = true;
}
writer.write(msg);
} catch (Exception ex) {
// We don't want to throw an exception here, but we
// report the exception to any registered ErrorManager.
reportError(null, ex, ErrorManager.WRITE_FAILURE);
}
|
public void | setEncoding(java.lang.String encoding)Set (or change) the character encoding used by this Handler.
The encoding should be set before any LogRecords are written
to the Handler.
super.setEncoding(encoding);
if (output == null) {
return;
}
// Replace the current writer with a writer for the new encoding.
flush();
if (encoding == null) {
writer = new OutputStreamWriter(output);
} else {
writer = new OutputStreamWriter(output, encoding);
}
|
protected synchronized void | setOutputStream(java.io.OutputStream out)Change the output stream.
If there is a current output stream then the Formatter's
tail string is written and the stream is flushed and closed.
Then the output stream is replaced with the new output stream.
if (out == null) {
throw new NullPointerException();
}
flushAndClose();
output = out;
doneHeader = false;
String encoding = getEncoding();
if (encoding == null) {
writer = new OutputStreamWriter(output);
} else {
try {
writer = new OutputStreamWriter(output, encoding);
} catch (UnsupportedEncodingException ex) {
// This shouldn't happen. The setEncoding method
// should have validated that the encoding is OK.
throw new Error("Unexpected exception " + ex);
}
}
|