Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.util.logging.Handler
Handler
publishes LogRecords
to
a sink, for example a file, the console or a network socket.
There are different subclasses of Handler
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.
Constructor Summary | |
|
Method Summary | |
abstract void |
|
abstract void |
|
String |
|
ErrorManager |
|
Filter |
|
Formatter |
|
Level |
|
boolean |
|
abstract void | |
protected void |
|
void |
|
void |
|
void | |
void |
|
void |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
protected Handler()
Constructs a Handler with a logging severity level ofLevel.ALL
, no formatter, no filter, and an instance ofErrorManager
managing errors.Specification Note: The specification of the JavaTM Logging API does not mention which character encoding is to be used by freshly constructed Handlers. The GNU implementation uses the default platform encoding, but other Java implementations might behave differently.
Specification Note: While a freshly constructed Handler is required to have no filter according to the specification,
null
is not a valid parameter forHandler.setFormatter
. Therefore, the following code will throw ajava.lang.NullPointerException
:Handler h = new MyConcreteSubclassOfHandler(); h.setFormatter(h.getFormatter());It seems strange that a freshly constructed Handler is not supposed to provide a Formatter, but this is what the specification says.
public abstract void close() throws SecurityException
Closes thisHandler
after having flushed the buffers. As soon asclose
has been called, aHandler
should not be used anymore. Attempts to publish log records, to flush buffers, or to modify theHandler
in any other way may throw runtime exceptions after callingclose
.In case of an I/O failure, the
ErrorManager
of thisHandler
will be informed, but the caller of this method will not receive an exception.
- Throws:
SecurityException
- if a security manager exists and the caller is not granted the permission to control the logging infrastructure.
public abstract void flush()
Forces any data that may have been buffered to the underlying output device.In case of an I/O failure, the
ErrorManager
of thisHandler
will be informed, but the caller of this method will not receive an exception.
public String getEncoding()
Returns the character encoding which this handler uses for publishing log records.
- Returns:
- the name of a character encoding, or
null
for the default platform encoding.
public ErrorManager getErrorManager()
Returns theErrorManager
that currently deals with errors originating from this Handler.
- Throws:
SecurityException
- if a security manager exists and the caller is not granted the permission to control the logging infrastructure.
public Filter getFilter()
Returns theFilter
that currently controls which log records are being published by thisHandler
.
- Returns:
- the currently active
Filter
, ornull
if no filter has been associated. In the latter case, log records are filtered purely based on their severity level.
public Formatter getFormatter()
Returns theFormatter
which will be used to localize the text of log messages and to substitute message parameters. AHandler
is encouraged, but not required to actually use an assignedFormatter
.
- Returns:
- the
Formatter
being used, ornull
if thisHandler
does not use formatters and no formatter has ever been set by callingsetFormatter
.
public Level getLevel()
Returns the severity level threshold for thisHandler
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 installedFilter
decides to discard it.
- Returns:
- the severity level below which all log messages will be discarded.
public boolean isLoggable(LogRecord record)
Checks whether aLogRecord
would be logged if it was passed to thisHandler
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 aFilter
has been installed, itsisLoggable
method is invoked. Subclasses ofHandler
can override this method to impose their own constraints.
- Parameters:
record
- theLogRecord
to be checked.
- Returns:
true
ifrecord
would be published bypublish
,false
if it would be discarded.
- Throws:
NullPointerException
- ifrecord
isnull
.
public abstract void publish(LogRecord record)
Publishes aLogRecord
to an appropriate sink, provided the record passes all tests for being loggable. TheHandler
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 thisHandler
will be informed, but the caller of this method will not receive an exception.
- Parameters:
record
- the log event to be published.
public void setEncoding(String encoding) throws SecurityException, UnsupportedEncodingException
Sets the character encoding which this handler uses for publishing log records. The encoding of aHandler
must be set before any log records have been published.
- Parameters:
encoding
- the name of a character encoding, ornull
for the default encoding.
- Throws:
SecurityException
- if a security manager exists and the caller is not granted the permission to control the logging infrastructure.
public void setFilter(Filter filter) throws SecurityException
Sets theFilter
for controlling which log records will be published by thisHandler
.
- Parameters:
filter
- theFilter
to use, ornull
to filter log records purely based on their severity level.
public void setFormatter(Formatter formatter) throws SecurityException
Sets theFormatter
which will be used to localize the text of log messages and to substitute message parameters. AHandler
is encouraged, but not required to actually use an assignedFormatter
.
- Parameters:
formatter
- the newFormatter
to use.
- Throws:
SecurityException
- if a security manager exists and the caller is not granted the permission to control the logging infrastructure.NullPointerException
- ifformatter
isnull
.
public void setLevel(Level level)
Sets the severity level threshold for thisHandler
. 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 installedFilter
decides to discard it.
- Parameters:
level
- the severity level below which all log messages will be discarded.
- Throws:
SecurityException
- if a security manager exists and the caller is not granted the permission to control the logging infrastructure.NullPointerException
- iflevel
isnull
.