Handler object takes log messages from a Logger and
exports them. It might for example, write them to a console
or write them to a file, or send them to a network logging service,
or forward them to an OS log, or whatever.
A Handler can be disabled by doing a setLevel(Level.OFF)
and can be re-enabled by doing a setLevel with an appropriate level.
Handler classes typically use LogManager properties to set
default values for the Handler's Filter, Formatter,
and Level. See the specific documentation for each concrete
Handler class.
Handler should be thread-safe. Handlers are
expected to be invoked concurrently from arbitrary threads. However,
over-use of synchronization may result in unwanted thread contention,
performance issues or even deadlocking.
In particular, subclasses should avoid acquiring locks around code which calls back to arbitrary user-supplied objects, especially during log record formatting. Holding a lock around any such callbacks creates a deadlock risk between logging code and user code.
As such, general purpose Handler subclasses should not synchronize
their publish(LogRecord) methods, or call super.publish()
while holding locks, since these are typically expected to need to process
and format user-supplied arguments.
| Modifier and Type | Field and Description |
|---|---|
| private volatile String | |
| private volatile ErrorManager | |
| private volatile Filter | |
| private volatile Formatter | |
| private volatile Level | |
| private final LogManager | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| protected | |
| pack-priv | Handler(Level
a default defaultLevel, Formatter Level to configure if one is
not found in LogManager configuration propertiesa default defaultFormatter, Formatter Formatter to configure if one is
not specified by specifiedFormatter parameter
nor found in LogManager configuration propertiesif not null, this is the formatter to configure specifiedFormatter)Package-private constructor for chaining from subclass constructors that wish to configure the handler with specific default and/or specified values. |
| Modifier and Type | Method and Description |
|---|---|
| public abstract void | |
| public abstract void | |
| public String | Returns: The encoding name. May be null, which indicates the default encoding should be used.Return the character encoding for this |
| public ErrorManager | Returns: the ErrorManager for this HandlerRetrieves the ErrorManager for this Handler. |
| public Filter | |
| public Formatter | |
| public Level | Returns: the level of messages being logged.Get the log level specifying which messages will be
logged by this |
| public boolean | Returns: true if theLogRecord would be logged.a record)LogRecord (may be null).Check if this |
| public abstract void | |
| protected void | reportError(String
a descriptive string (may be null) msg, Exception an exception (may be null) ex, int an error code defined in ErrorManager code)Protected convenience method to report an error to this Handler's ErrorManager. |
| public synchronized void | setEncoding(String
The name of a supported character encoding.
May be null, to indicate the default platform encoding. encoding)Set the character encoding used by this |
| public synchronized void | |
| public synchronized void | |
| public synchronized void | |
| public synchronized void |
| encoding | back to summary |
|---|---|
| private volatile String encoding | |
| errorManager | back to summary |
|---|---|
| private volatile ErrorManager errorManager | |
| filter | back to summary |
|---|---|
| private volatile Filter filter | |
| formatter | back to summary |
|---|---|
| private volatile Formatter formatter | |
| logLevel | back to summary |
|---|---|
| private volatile Level logLevel | |
| manager | back to summary |
|---|---|
| private final LogManager manager | |
| offValue | back to summary |
|---|---|
| private static final int offValue | |
| Handler | back to summary |
|---|---|
| protected Handler() Default constructor. The resulting | |
| Handler | back to summary |
|---|---|
| pack-priv Handler(Level defaultLevel, Formatter defaultFormatter, Formatter specifiedFormatter) Package-private constructor for chaining from subclass constructors that wish to configure the handler with specific default and/or specified values.
| |
| close | back to summary |
|---|---|
| public abstract void close() Close the
The close method will perform a | |
| flush | back to summary |
|---|---|
| public abstract void flush() Flush any buffered output. | |
| getEncoding | back to summary |
|---|---|
| public String getEncoding() Return the character encoding for this
| |
| getErrorManager | back to summary |
|---|---|
| public ErrorManager getErrorManager() Retrieves the ErrorManager for this Handler.
| |
| getFilter | back to summary |
|---|---|
| public Filter getFilter() Get the current
| |
| getFormatter | back to summary |
|---|---|
| public Formatter getFormatter() Return the
| |
| getLevel | back to summary |
|---|---|
| public Level getLevel() Get the log level specifying which messages will be
logged by this
| |
| isLoggable | back to summary |
|---|---|
| public boolean isLoggable(LogRecord record) Check if this
This method checks if the
| |
| publish | back to summary |
|---|---|
| public abstract void publish(LogRecord record) Publish a
The logging request was made initially to a
The API Note To avoid the risk of deadlock, implementations of this method
should avoid holding any locks while calling out to application code,
such as the formatting of
| |
| reportError | back to summary |
|---|---|
| protected void reportError(String msg, Exception ex, int code) Protected convenience method to report an error to this Handler's ErrorManager. | |
| setEncoding | back to summary |
|---|---|
| public synchronized void setEncoding(String encoding) throws UnsupportedEncodingException Set the character encoding used by this
The encoding should be set before any
| |
| setErrorManager | back to summary |
|---|---|
| public synchronized void setErrorManager(ErrorManager em) Define an ErrorManager for this Handler. The ErrorManager's "error" method will be invoked if any errors occur while using this Handler.
| |
| setFilter | back to summary |
|---|---|
| public synchronized void setFilter(Filter newFilter) Set a
For each call of
| |
| setFormatter | back to summary |
|---|---|
| public synchronized void setFormatter(Formatter newFormatter) Set a
Some
| |
| setLevel | back to summary |
|---|---|
| public synchronized void setLevel(Level newLevel) Set the log level specifying which message levels will be
logged by this
The intention is to allow developers to turn on voluminous
logging, but to limit the messages that are sent to certain
| |