java.lang.Object | +--java.util.logging.Handler
void | close() Closes this |
void | flush() Forces any data that may have been buffered to the underlying output device. |
java.lang.String | getEncoding() Returns the character encoding which this handler uses for publishing log records. |
java.util.logging.ErrorManager | getErrorManager() Returns the |
java.util.logging.Filter | getFilter() Returns the |
java.util.logging.Formatter | getFormatter() Returns the |
java.util.logging.Level | getLevel() Returns the severity level threshold for this |
boolean | isLoggable(java.util.logging.LogRecord record) Checks whether a |
void | publish(java.util.logging.LogRecord record) Publishes a |
void | reportError(java.lang.String message, java.lang.Exception ex, int code) |
void | setEncoding(java.lang.String encoding) Sets the character encoding which this handler uses for publishing log records. |
void | setErrorManager(java.util.logging.ErrorManager manager) |
void | setFilter(java.util.logging.Filter filter) Sets the |
void | setFormatter(java.util.logging.Formatter formatter) Sets the |
void | setLevel(java.util.logging.Level level) Sets the severity level threshold for this |
public void close()
Handler
after having flushed
the buffers. 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.
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.
public String getEncoding()
public ErrorManager getErrorManager()
ErrorManager
that currently deals
with errors originating from this Handler.
SecurityException
- if a security manager exists and
the caller is not granted the permission to control
the logging infrastructure.public Filter getFilter()
Filter
that currently controls which
log records are being published by this Handler
.
Filter
, or
null
if no filter has been associated.
In the latter case, log records are filtered purely
based on their severity level.public Formatter getFormatter()
Formatter
which will be used to
localize the text of log messages and to substitute
message parameters. A Handler
is encouraged,
but not required to actually use an assigned
Formatter
.
Formatter
being used, or
null
if this Handler
does not use formatters and no formatter has
ever been set by calling setFormatter
.public Level getLevel()
Handler
All log records with a lower severity level will be discarded;
a log record of the same or a higher level will be published
unless an installed Filter
decides to discard it.
public boolean isLoggable(java.util.logging.LogRecord record)
LogRecord
would be logged
if it was passed to this Handler
for publication.
The Handler
implementation considers a record as
loggable if its 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 Handler
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 an appropriate sink,
provided the record passes all tests for being loggable. The
Handler
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.
record
- the log event to be published.protected void reportError(java.lang.String message, java.lang.Exception ex, int code)
Parameters:message
- ex
- code
- public void setEncoding(java.lang.String encoding)
Handler
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 logging infrastructure.public void setErrorManager(java.util.logging.ErrorManager manager)
Parameters:manager
- public void setFilter(java.util.logging.Filter filter)
Filter
for controlling which
log records will be published by this Handler
.
filter
- Filter
to use, or
null
to filter log records purely based
on their severity level.public void setFormatter(java.util.logging.Formatter formatter)
Formatter
which will be used to
localize the text of log messages and to substitute
message parameters. A Handler
is encouraged,
but not required to actually use an assigned
Formatter
.
formatter
- the new Formatter
to use.SecurityException
- if a security manager exists and
the caller is not granted the permission to control
the logging infrastructure.NullPointerException
- if formatter
is
null
.public void setLevel(java.util.logging.Level level)
Handler
.
All log records with a lower severity level will be discarded;
a log record of the same or a higher level will be published
unless an installed Filter
decides to discard it.
level
- the severity level below which all log messages
will be discarded.SecurityException
- if a security manager exists and
the caller is not granted the permission to control
the logging infrastructure.NullPointerException
- if level
is
null
.
Handler
publishesLogRecords
to a sink, for example a file, the console or a network socket. There are different subclasses ofHandler
to deal with different kinds of sinks.FIXME: Are handlers thread-safe, or is the assumption that only loggers are, and a handler can belong only to one single logger? If the latter, should we enforce it? (Spec not clear). In any case, it needs documentation.