java.lang.Object | +--java.util.logging.Handler | +--java.util.logging.StreamHandler
StreamHandler() Creates a |
StreamHandler(java.io.OutputStream out, java.util.logging.Formatter formatter) Creates a |
void | close() Closes this |
void | flush() Forces any data that may have been buffered to the underlying output device. |
boolean | isLoggable(java.util.logging.LogRecord record) Checks whether or not a |
void | publish(java.util.logging.LogRecord record) Publishes a |
void | setEncoding(java.lang.String encoding) Sets the character encoding which this handler uses for publishing log records. |
void | setOutputStream(java.io.OutputStream out) Changes the output stream to which this handler publishes logging records. |
public StreamHandler()
StreamHandler
without an output stream.
Subclasses can later use #setOutputStream(java.io.OutputStream) to associate an output
stream with this StreamHandler.
public StreamHandler(java.io.OutputStream out, java.util.logging.Formatter formatter)
StreamHandler
that formats log messages
with the specified Formatter and publishes them to the specified
output stream.
out
- the output stream to which the formatted log messages
are published.formatter
- the Formatter
that will be used
to format log messages.public void close()
StreamHandler
after having forced any
data that may have been buffered to the underlying output
device.
As soon as close
has been called,
a Handler
should not be used anymore. Attempts
to publish log records, to flush buffers, or to modify the
Handler
in any other way may throw runtime
exceptions after calling close
.
In case of an I/O failure, the ErrorManager
of this Handler
will be informed, but the caller
of this method will not receive an exception.
If a StreamHandler
that has been closed earlier
is closed a second time, the Sun J2SE 1.4 reference can be
observed to silently ignore the call. The GNU implementation,
however, intentionally behaves differently by informing the
ErrorManager
associated with this
StreamHandler
. Since the condition indicates a
programming error, the programmer should be informed. It also
seems extremely unlikely that any application would depend on the
exact behavior in this rather obscure, erroneous case --
especially since the API specification does not prescribe what is
supposed to happen.
SecurityException
- if a security manager exists and
the caller is not granted the permission to control
the logging infrastructure.public void flush()
In case of an I/O failure, the ErrorManager
of this Handler
will be informed, but the caller
of this method will not receive an exception.
If a StreamHandler
that has been closed earlier
is closed a second time, the Sun J2SE 1.4 reference can be
observed to silently ignore the call. The GNU implementation,
however, intentionally behaves differently by informing the
ErrorManager
associated with this
StreamHandler
. Since the condition indicates a
programming error, the programmer should be informed. It also
seems extremely unlikely that any application would depend on the
exact behavior in this rather obscure, erroneous case --
especially since the API specification does not prescribe what is
supposed to happen.
public boolean isLoggable(java.util.logging.LogRecord record)
LogRecord
would be logged
if it was passed to this StreamHandler
for publication.
The StreamHandler
implementation first checks
whether a writer is present and the handler's level is greater
than or equal to the severity level threshold. In a second step,
if a Filter has been installed, its Filter#isLoggable(LogRecord) isLoggable method is
invoked. Subclasses of StreamHandler
can override
this method to impose their own constraints.
record
- the LogRecord
to be checked.true
if record
would
be published by {@link #publish(LogRecord) publish},
false
if it would be discarded.NullPointerException
- if record
is
null
.public void publish(java.util.logging.LogRecord record)
LogRecord
to the associated output
stream, provided the record passes all tests for being loggable.
The StreamHandler
will localize the message of the
log record and substitute any message parameters.
Most applications do not need to call this method directly. Instead, they will use use a Logger, which will create LogRecords and distribute them to registered handlers.
In case of an I/O failure, the ErrorManager
of this Handler
will be informed, but the caller
of this method will not receive an exception.
If a log record is being published to a
StreamHandler
that has been closed earlier, the Sun
J2SE 1.4 reference can be observed to silently ignore the
call. The GNU implementation, however, intentionally behaves
differently by informing the ErrorManager
associated
with this StreamHandler
. Since the condition
indicates a programming error, the programmer should be
informed. It also seems extremely unlikely that any application
would depend on the exact behavior in this rather obscure,
erroneous case -- especially since the API specification does not
prescribe what is supposed to happen.
record
- the log event to be published.public void setEncoding(java.lang.String encoding)
StreamHandler
must be
set before any log records have been published.
encoding
- the name of a character encoding, or null
for the default encoding.SecurityException
- if a security manager exists and
the caller is not granted the permission to control the
the logging infrastructure.IllegalStateException
- if any log records have been
published to this StreamHandler
before.protected void setOutputStream(java.io.OutputStream out)
out
- SecurityException
- if a security manager exists and
the caller is not granted the permission to control
the logging infrastructure.NullPointerException
- if out
is null
.
StreamHandler
publishesLogRecords
to a instances ofjava.io.OutputStream
.